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 handleThumbnailClicks() { | |
$('.thumbnail').click(function(event) { | |
var imgSrc = $(event.currentTarget).find('img').attr('src'); | |
$('.hero img').attr('src', imgSrc); | |
}) | |
} | |
$(function() { | |
handleThumbnailClicks(); | |
}); |
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
var fizzString = 'fizz'; | |
var buzzString = 'buzz'; | |
var fizzBuzzString = 'fizzbuzz'; | |
function getFizzBuzzValue(num) { | |
var val = num; | |
if (num % 15 === 0) { | |
val = fizzBuzzString; | |
} else if (num % 5 === 0) { | |
val = buzzString; | |
} else if (num % 3 === 0) { | |
val = fizzString; | |
} | |
return val; | |
} | |
function makeFizzBuzzArray(num) { | |
var result = []; | |
for (var i=1; i<=num; i++) { | |
result.push(getFizzBuzzValue(getFizzBuzzValue(i))); | |
} | |
return result; | |
} | |
function doFizzBuzz(num) { | |
var fizzBuzzArray = makeFizzBuzzArray(num); | |
fizzBuzzArray.forEach(function(item) { | |
var newElem = $( | |
'<div class="fizz-buzz-item"><span>' + item + '</span></div>'); | |
if (item === fizzString || item === buzzString || item === fizzBuzzString) { | |
newElem.addClass(item); | |
} | |
$(".js-results").append(newElem); | |
}) | |
} | |
function handleFormSubmit() { | |
$('#number-chooser').submit(function(event) { | |
event.preventDefault(); | |
// in case there's already results | |
$(".js-results").empty(); | |
var choice = parseInt( $(event.currentTarget).find( | |
'input[name="number-choice"]').val()); | |
doFizzBuzz(choice); | |
}); | |
} | |
$(function() { | |
handleFormSubmit(); | |
}); |
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 handleBulbClicks() { | |
$('.lightbulb').click(function(event){ | |
$('.lightbulb').removeClass('bulb-on'); | |
$(event.currentTarget).addClass('bulb-on') | |
}); | |
} | |
$(function() { | |
handleBulbClicks(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment