-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·69 lines (60 loc) · 1.61 KB
/
script.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
var speed = 1000;
var currScore = 0;
var maxPossScore = 0;
var interval;
$(function() {
alert("hello");
bindKeyPress();
startGame();
});
function bindKeyPress()
{
$(document).on("keyup", function(event) {
var keyPressed = event.which;
console.log(keyPressed);
if (keyPressed > 64 && keyPressed < 91) {
if ($("#"+keyPressed).attr("purpose") == "curr")
{
$("#"+keyPressed).stop(true).css({marginTop: '5px', opacity:0}).removeAttr("purpose");
currScore = currScore + 1;
$("#score").text(currScore);
maxPossScore = maxPossScore + 1;
console.log(maxPossScore+" max")
if(currScore%3 === 0)
{
clearInterval(interval);
speed = speed*.9;
interval = setInterval(temp, speed);
console.log(speed+" speed");
}
console.log(currScore + " curr");
}
}
});
}
function startGame()
{
interval = setInterval(temp, speed);
}
function temp()
{
animateLetter();
if(maxPossScore-currScore >= 5)
{
clearInterval(interval);
$("#status").text("over");
$("#lettersCont li").stop().css({marginTop: '5px', opacity:0}).removeAttr("purpose");
$("#lettersCont").hide();
}
}
function animateLetter()
{
var letter = Math.floor(Math.random() * 26) + 65;
$("#" + letter).animate({ marginTop: '200px', opacity:1},
{ duration: 2000, complete: function(){
maxPossScore = maxPossScore + 1;
$("#" + letter).css({marginTop: '5px', opacity:0}).removeAttr("purpose");
console.log(maxPossScore+" maximum")
}}).attr("purpose", "curr");
console.log("random = " + letter);
}