-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (46 loc) · 1.84 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
//https://javascript.info/strict-mode or
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
//This program is written very naively - on purpose
//There will be future excercises to improve the program design and structure
const prompt = require('prompt-sync')({sigint: true});
//Apple Banana Cherry Diamond
const reel1=['Apple','Banana','Cherry','Diamond','Cherry','Diamond','Apple','Apple','Cherry','Banana']
const reel2=['Apple','Diamond','Cherry','Banana','Banana','Cherry','Apple','Banana','Apple','Cherry']
const reel3=['Cherry','Banana','Cherry','Apple','Apple','Banana','Diamond','Apple','Cherry','Banana']
let money = 100
let started=process.hrtime() //returns a [seconds][nanoseonds] tuple
while (money) {
console.log('You have £' + money )
prompt('Press enter to spin the wheels')
money = money - 1 //Pay £1 to play
let p1 = Math.floor(Math.random() * 10)
let p2 = Math.floor(Math.random() * 10)
let p3 = Math.floor(Math.random() * 10)
console.log(reel1[p1] + ' ' + reel2[p2] + ' ' + reel3[p3])
if (reel1[p1]==reel2[p2] && reel2[p2]==reel3[p3]){
console.log ('You win :o)')
if (reel1[p1]=='Apple'){
money = money + 2
console.log ('£2')
}
else if (reel1[p1]=='Banana'){
money = money + 3
console.log ('£3')
}
else if (reel1[p1]=='Cherry'){
money = money + 5
console.log ('£5')
}
else if (reel1[p1]=='Diamond'){
money = money + 20
console.log ('£20')
}
}
else{
console.log('You lose :o(')
}
}
console.log ("You are out of money - gambling is a fools game")
let took=process.hrtime(started)
console.log (took[0] +" seconds and " + took[1] /1e6 + " milliseconds")