-
Notifications
You must be signed in to change notification settings - Fork 0
/
carys-maths.html
89 lines (83 loc) · 2.64 KB
/
carys-maths.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Carys Mathcs</title>
<meta name="author" content="Tom Morgan">
<style type="text/css" media="screen">
.hidden {display:none;}
* {margin:0px;padding:0px;font-size:150%;font-family:sans-serif;}
p {
margin-bottom:0.5em;
}
#main {
width:1000px;
margin:20px auto;
}
input {
width:100%;
}
.red {color:red;}
.grn {color:green;}
button {
font-size:100%;
padding:20px;
text-transform:uppercase;
font-weight:bold;
cursor:pointer;
}
#score {
float:right;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function()
{
var number, divisor, answer, score = 0;
function startAgain()
{
number = 2 * Math.ceil((Math.random() * 50));
divisor = 2;
answer = number/divisor;
var format = "What is %n% divided by %d%?";
format = format.replace('%n%', number);
format = format.replace('%d%', divisor);
$('#question').html(format);
}
$('#answer').keyup(function()
{
var val = parseInt($(this).val(),10);
console.log(val);
if (val == answer)
{
$('#feedback').fadeIn().html('Well done!').addClass('grn').removeClass('red');
$('#again').fadeIn();
} else {
$('#feedback').fadeIn().html('Not quite! Keep trying').addClass('red').removeClass('grn');
}
}).focus();
$('#again').click(function(e)
{
e.preventDefault();
$('#answer').val('').focus();
$('#feedback').fadeOut();
$('#again').fadeOut();
startAgain();
score++;
$("#score").html(score);
});
startAgain();
});
</script>
</head>
<body>
<div id="main">
<p id="question"></p>
<p><input type="text" id="answer" value="" /></p>
<p id="score">0</p>
<p id="feedback" class="red hidden"></p>
<button id="again" class="hidden">try again?</button>
</div>
</body>
</html>