-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.html
63 lines (50 loc) · 1.83 KB
/
fizzbuzz.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FizzBuzz!</title>
<script src="scripts/auto-theme.js"></script>
<script src="https://embed.runkit.com"></script>
<link href="https://fonts.googleapis.com/css?family=Merriweather%7CLato" rel="stylesheet">
<link rel="stylesheet" href="styles.css" type="text/css">
<link rel="shortcut icon" href="favicon.ico" type="image/vnd.microsoft.icon">
</head>
<body class="wide">
<nav>
<h1>FizzBuzz!</h1>
<p><a href="https://runkit.com/willwm/fizzbuzz">runkit.com/willwm/fizzbuzz</a></p>
<code id="runkit">
</code>
</nav>
<script>
document.addEventListener("DOMContentLoaded", function () {
const fizzbuzz = document.getElementById('fizzbuzz');
const notebook = RunKit.createNotebook({
// the parent element for the new notebook
element: document.getElementById("runkit"),
// specify the source of the notebook
source: fizzbuzz.textContent,
})
});
</script>
<!-- FizzBuzz implementation -->
<script id="fizzbuzz">
// Based on FizzBuzz description from: https://en.wikipedia.org/wiki/Fizz_buzz
function fizzbuzz(val) {
let output = '';
if (val % 3 === 0) { output += 'Fizz'; }
if (val % 5 === 0) { output += 'Buzz'; }
if (output === '') { output = `${val}`; }
return output;
}
function runner(iterations) {
for (i = 1; i <= iterations; i++) {
const result = fizzbuzz(i);
console.log(`${i}: ${result}`);
}
}
runner(100);
</script>
</body>
</html>