DEV Community 👩‍💻👨‍💻

Cover image for Let's write a fun CLI quiz
Adhishreya P
Adhishreya P

Posted on

Let's write a fun CLI quiz

what is require()??

require is a function that allows us to work with modules defined in separate files. If u are familiar with C then require is similar to include.
So the functionality involves reading the specified JavaScript file and returning the export object of the file.

var code=require('readline-sync')

Basically, it allows to have interaction with the user via the console in a synchronous manner.

To get the user input one can use 'question'

var readInput=require('readline-sync');

var input =readInput.question('Helooooo what's ur name?');
//the user's response is stored in the variable 'input'

What is chalk??

It basically a styling library for your terminal. You can also chain multiple styles!!

var chalk=require('chalk')

console.log("we are trying out chalk"))

read more about it here.... Chalk js Documentation


A method that allows a function to be executed on every element of the list just as any regular for loop does.

A basic syntax.

array.forEach(function(currentValue, index, arr))

  1. currentValue= the current element being worked on
  2. index = index of the current element
  3. arr=array object the current object belongs to





The complete code can be found here

Top comments (0)

Visualizing Promises and Async/Await 🤯

async await

☝️ Check out this all-time classic DEV post