Created
June 26, 2017 22:18
-
-
Save anonymous/d9d4289209790ee8e2adc8f5d95c29ae to your computer and use it in GitHub Desktop.
fizzbuzz drillwJS created by dtstanley - https://repl.it/GiQ8/694
This file contains 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
* { | |
box-sizing: border-box; | |
font-family: sans-serif | |
} | |
main { | |
max-width: 960px; | |
margin: 0 auto; | |
min-width: 250px; | |
padding: 30px; | |
} | |
p { | |
max-width: 500px; | |
} | |
.fizz-buzz-item { | |
display: block; | |
float: left; | |
width: 80px; | |
height: 80px; | |
text-align: center; | |
border: 1px solid grey; | |
margin-right: 5px; | |
margin-bottom: 5px; | |
} | |
.fizz-buzz-item span { | |
vertical-align: middle; | |
line-height: 80px; | |
} | |
.fizz, .fizzbuzz { | |
border: 4px solid green; | |
} | |
.buzz, .fizzbuzz { | |
background-color: #D5F5E3; | |
} |
This file contains 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> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>fizzbuzz drill</title> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js" | |
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
crossorigin="anonymous"></script> | |
<link href="index.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<main> | |
<h1>Fizz Buzz</h1> | |
<section> | |
<p>In this game, you enter a positive number, and I count from 0 to that number, subbing in "fizz" if it's divisible by 3, "buzz" if it's divisible by 5, and "fizzbuzz" if it's divisible by both</p> | |
<form id="number-chooser" action="www.somewhere.com"> | |
<label for="number-choice">Choose a positive number</label> | |
<input id="number-choice" name="number-choice" type="number" required /> | |
<input type="submit" /> | |
</form> | |
</section> | |
<section> | |
<h2>Results</h2> | |
<div class="js-results"></div> | |
</section> | |
</main> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains 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
function fizzBuzz(num){ | |
var fbArray = []; | |
/*FizzBuzz - Intermediate - using if statements only*/ | |
for (var counter =1; counter <=num; counter++){ | |
//set the default value first | |
var msg = counter; | |
//over-write the default values as we go through the logic | |
if (counter %5 ===0){ | |
msg = "Buzz"; | |
} | |
if (counter % 3===0){ | |
msg = "Fizz"; | |
} | |
if (counter % 15 ===0 ){ | |
msg = "FizzBuzz"; | |
} | |
fbArray.push(msg); | |
//console.log(msg); | |
console.log(fbArray); | |
// $(".js-results").append(fbArray); | |
} | |
var fizzBuzzArray = fbArray; | |
fizzBuzzArray.forEach(function(item){ | |
var printItem =$( | |
'<div class= "fizz-buzz-item"><span>' + item + '</span><div>' | |
); | |
$(".js-results").append(printItem); | |
}); | |
return fbArray; | |
} | |
$('#number-chooser').submit(function(event) { | |
// this stops the default form submission behavior | |
event.preventDefault(); | |
//in case there is already a result | |
$(".js-results").empty(); | |
var userInput = $('#number-choice').val(); | |
fizzBuzz(userInput); | |
// $(".js-results").append(userInput); | |
//$(".js-results").text(userInput); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment