<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</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="https://code.jquery.com/jquery-3.1.0.js"></script>
</body>
</html>
* {
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 {
color: #fff;
background-color: #76f2be;
}
function fizzBuzz(countTo) {
var arr = []
for (i = 1; i <= countTo; i++) {
if (i%15 === 0) {
arr.push('fizzbuzz')
} else if (i%3 === 0) {
arr.push('fizz')
} else if (i%5 === 0) {
arr.push('buzz')
} else {
arr.push(i)
}
}
return arr
}
$('#number-chooser').submit(function(event) {
countTo = $('#number-choice').val()
var results = fizzBuzz(countTo)
console.log($(this))
$.each(results.arr), function(index, value) {
console.log($(this))
var fizzBuzzItem = $('.js-results').append('<div class="fizz-buzz-item"><span>' + $(this).value + '</span></div>')
return fizzBuzzItem
}
})
/*
Instructions:
This time you'll create an event listener that listens for
when a user submits a form indicating how high to count.
This event should cause the program to create the FizzBuzz sequence
up to the number requested by the user.
For each element in the FizzBuzz sequence, your code should insert an element into
the .js-results div that looks like this:
<div class="fizz-buzz-item">
<span>1</span>
</div>
If the element's content is the word "fizz", the div with .fizz-buzz-item should also get
the class .fizz applied. If the element's content is the word "buzz" it should get
the class ".buzz" applied. And if its content is the word "fizzbuzz", it should get
the class "fizzbuzz" applied.
*/
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |