- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJavaScript.js
More file actions
Latest commit
27 lines (23 loc) · 558 Bytes
/
Copy pathJavaScript.js
File metadata and controls
27 lines (23 loc) · 558 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
import{createInterface}from'readline'
constrl=createInterface({
input: process.stdin,
output: process.stdout
})
constanswer=Math.floor(Math.random()*101)
letcounter=1
functionaskGuess(){
rl.question("Guess a number between 0 and 100: ",guess=>{
if(guess<answer){
console.log("Too low!")
counter++
askGuess()
}elseif(guess>answer){
console.log("Too high!")
counter++
askGuess()
}else{
console.log(`Correct! You took ${counter} guesses.`)
}
})
}
askGuess()