-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappRead.js
More file actions
28 lines (25 loc) · 826 Bytes
/
Copy pathappRead.js
File metadata and controls
28 lines (25 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const readline = require('readline');
const rl = readline.createInterface({input : process.stdin,
output : process.stdout });
let num1 = Math.floor((Math.random()*10)+ 1);
let num2 = Math.floor((Math.random()*10)+ 1);
let ans = num1 + num2;
rl.question(`What is the sum of ${num1}+ ${num2}? \n`,(userInput)=>{
if(userInput.trim() == ans){
rl.close();
}else{
rl.setPrompt('Invalid entry.Pease try again...\n');
rl.prompt();
rl.on('line',(userInput)=>{
if(userInput.trim() == ans){
rl.close();
}else{
rl.setPrompt('Invalid response.Pease try again...\n');
rl.prompt();
}
});
}
});
rl.on('close',()=>{
console.log('Correct!!!');
});