Skip to content

Instantly share code, notes, and snippets.

@oddurs
Created April 28, 2014 15:59
Show Gist options
  • Save oddurs/11376315 to your computer and use it in GitHub Desktop.
Save oddurs/11376315 to your computer and use it in GitHub Desktop.
FizzBuzz (Epicodus)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FizzBuzz</title>
<meta name="description" content="The FizzBuzz Exercise">
<meta name="author" content="Oddur Sigurdsson">
</head>
<body>
<h1>FizzBuzz</h1>
<script type='text/javascript'>
var max = prompt("How far do you want to FizzBuzz?");
// (starting variable, condition, execute each time)
for (i = 1; i <= max; i++) {
// if i has no remainder when divided by 15 (or 3 AND 5)
if (i % 15 == 0){
document.write("FizzBuzz" + "<br>");
}
else {
// if i has no remainder when divided by 3
if (i % 3 == 0) {
document.write("Fizz" + "<br>");
}
// else if i has no remainder when divided by 5
else if (i % 5 == 0){
document.write("Buzz" + "<br>");
}
// otherwise just print i
else {
document.write(i + "<br>");
}
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment