Created
April 28, 2014 15:59
-
-
Save oddurs/11376315 to your computer and use it in GitHub Desktop.
FizzBuzz (Epicodus)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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