This repository has been archived by the owner on Jan 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratespiel.js
85 lines (73 loc) · 2.04 KB
/
ratespiel.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
randomNumber = Math.floor(Math.random() * 100 + 1);
function initialise()
{
rounds = 7;
$("#roundCount").text(rounds);
$("#result").empty();
won = false;
//randomNumber = Math.floor(Math.random() * 100 + 1);
$("#checkglyph").attr("class", "glyphicon glyphicon-play-circle");
$("#check").attr("class", "btn btn-success");
};
initialise();
$("#start").on("click", initialise);
function game(){
let input = $("#user-input").val();
$("#user-input").val('');
if(rounds && input && !won && Boolean(String(input).match('^[1-9][0-9]{0,2}$')) && input <= 100 )
{
--rounds;
$("#roundCount").text(rounds);
switch(Math.sign(randomNumber-input)){
case 0:
//korrekt
//Listeneintrag einfuegen
$("#result").append(
'<li class="list-group-item list-group-item-success">\
<span class="badge">'+
input +
'</span> Die Zahl ist Korrekt\
</li>');
//Button Anpassen
$("#checkglyph").attr("class", "glyphicon glyphicon-ok");
$("#check").attr("class", "btn btn-success");
won = true;
break;
case -1:
//to high
//Listeneintrag einfuegen
$("#result").append(
'<li class="list-group-item list-group-item-danger">\
<span class="badge">'+
input +
'</span>Die Zahl ist zu hoch\
</li>');
//Button Anpassen
$("#checkglyph").attr("class", "glyphicon glyphicon-remove");
$("#check").attr("class", "btn btn-danger");
break;
case 1:
//to low
//Listeneintrag einfuegen
$("#result").append(
'<li class="list-group-item list-group-item-info"> \
<span class="badge">'+
input +
'</span> Die Zahl ist zu niedrig \
</li>');
//Button Anpassen
$("#checkglyph").attr("class", "glyphicon glyphicon-remove");
$("#check").attr("class", "btn btn-danger");
break;
}
if(!rounds && !won){
$("#result").append("<li class=\"list-group-item list-group-item-warning\">Leider verloren</li>");
}
}
}
$("#check").on("click", game);
$(document).on("keypress", function(key) {
if(key.which == 13){
game();
}
});