-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathquizzy.html
37 lines (33 loc) · 1.26 KB
/
quizzy.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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<h2>You have now drunk <span id='userscore'>0</span>g of sugar</h2>
<p id='intro'>See how much sugar you can hoover up by choosing the sweetest coffee shop beverages!</p>
<p class='drink' data-sugar='99'>Starbucks Hot Mulled Fruit - Grape with Chai, Orange and Cinnamon Venti</p>
<p class='drink' data-sugar='88'>Starbucks Hot Mulled Fruit - Apple with Chai, Dried Apple and Cinnamon Venti</p>
<p id='explained'><a href="http://www.theguardian.com/business/2016/feb/17/cafe-chains-selling-drinks-25-teaspoons-sugar-starbucks-costa-coffee">Read more about 'The cafes serving drinks with 25 teaspoons of sugar per cup' here</a></p>
<script>
$(document).ready(function(){
console.log('jquery running!');
var score = 0
$(function(){
$('p.drink').on('click', function(){
console.log(score);
var sugar = $(this).attr('data-sugar');
console.log(sugar);
console.log(parseInt(sugar));
score = score+parseInt(sugar)
console.log(score);
$('span#userscore').text(score);
$('p[data-sugar="'+sugar+'"').text('This drink has '+sugar+'g of sugar')
if (score > 150) {
$('h2').append('. You are very fat. Well done')
}
});
});
});
</script>
</body>
</html>