forked from alexpelan/ScriptEdBasketball
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasketball.js
More file actions
75 lines (47 loc) · 1.11 KB
/
basketball.js
File metadata and controls
75 lines (47 loc) · 1.11 KB
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
function promptForPlayerName (player){
var name = prompt("What is " + player + " name?")
if(name.length>15)
alert("Wow , that's a long name!")
return name;
}
function tryTwoPointShot (){
var random1=Math.random();
var random2=Math.random();
if (random1 > 0.2 && random2 > 0.2){
return true;
}
else{
return false;
}
}
function tryThreePointShot(){
var random1=Math.random();
var random2=Math.random();
if(random1 <= 0.2 || random2 >=0.8){
return true;
}
else{
return false;
}
}
function getShotString(basketball, score, answer){
if(answer){
return(basketball + " attempted a " + score + " pointer it was good ");
}
else {
return(basketball + " attempted a " + score + " pointer it was not good ");
}
}
function updateScore(answer, score, worth ){
if(answer){
return(score+worth);
}
else{
return(score)
}
}
function isEndOfGame(score, name){
if(score>=20){
alert(" The game is over " + name + " has won ");
}
}