-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstJS.js
123 lines (77 loc) · 2.28 KB
/
firstJS.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var guesses = [];
var guessCounter = 0
var guessLimit = 5
function calcAnswer(){
return answer = Math.round(Math.random() * 100);
}
$(document).ready(function(){
//var answer = Math.round(Math.random() * 100);
calcAnswer();
function resetGameFunc(){
guessCounter = 0;
guesses = [];
calcAnswer();
alert("The game has been reset!")
}
$('input').on("click",function(){
$(this).val("");
});
$('#getAnswer').on("click",function(){
$("#exclamation").text("The answer is " + answer+ "! Try playing again!")
})
$('#newgame').on("click",function(){
var resetGame = false;
resetGame = confirm("Are you sure you want to reset the game?")
if (resetGame){
resetGameFunc();
}
})
$('#submit').on("click",function(){
var ansGuesses = false;
for(var i=0;i<guesses.length;i++){
if($('#guess_input').val()===guesses[i]){
ansGuesses = true;
}
}
if(isNaN($('#guess_input').val()) || $('#guess_input').val()>100 || $('#guess_input').val()<0){
alert("That's not an acceptable number. Please input a number between 1-100!")
}
else if(ansGuesses){
alert("You have already guessed this number! Try another guess!")
}
else{
if(Number($('#guess_input').val()) === answer){
$('#exclamation').text("Holy Shit! You did it! Congratulations. The game is automatically resetting!");
$('#exclamation').append('<p class="click-me" onclick="onImageClicked(this)"><img src="test.jpg" border="0" width="500" height="159"></p>');
resetGameFunc();
}
else{
if((guessCounter) == (guessLimit-1)){
alert("You're out of guesses! Restart the game");
resetGameFunc();
}
else{
guesses.push($('#guess_input').val());
guessCounter++;
$("#guessOuput").text("Good Guess! Try again!");
$('#numGuessesOutput').text("You have "+(guessLimit-guessCounter)+" guesses left!");
$('#whichGuesses').text("You have gusses the following numbers: "+guesses);
if($('#guess_input').val()>answer){
$('#hotOutput').text("You're guess is too high")
}
else{
$('#hotOutput').text("You're guess is too low")
}
}
}
}
})
$("#hint").on("click",function(){
if(answer%2===0){
alert("The answer is an even number");
}
else{
alert("The answer is an odd number!");
}
})
})