-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess.js
48 lines (30 loc) · 885 Bytes
/
guess.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const prompt = require('prompt-sync')();
let jeu = {
chance : 3,
compteur : 0,
min : 0,
max : 9,
msgGagnant : 'Vous avez gagné ! ',
msgPerdant : 'Vous avez perdu ',
msgEssai : 'Réessayez '
}
//let chance = 3;
//let count = 0;
//let min = 0;
//let max = 9;
let nbSecret = Math.round(Math.random() * (jeu.max - jeu.min) + jeu.min);
while(jeu.compteur < jeu.chance){
let x = prompt('Entrez un nombre : ');
x = Number(x);
jeu.compteur++;
if(x == nbSecret){
console.log(jeu.msgGagnant);
break;
} else {
if(jeu.compteur < jeu.chance ){
console.log(jeu.msgEssai);
} else {
console.log(jeu.msgPerdant);
}
}
}