Created
December 21, 2016 09:27
-
-
Save nikhilmufc7/a2daf827f2ffe7df55927f80f5bdb797 to your computer and use it in GitHub Desktop.
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
function handleThumbnailClicks() { | |
$('.thumbnail').click(function(event) { | |
var imgSrc = $(event.currentTarget).find('img').attr('src'); | |
$('.hero img').attr('src', imgSrc); | |
}) | |
} | |
$(function() { | |
handleThumbnailClicks(); | |
}); |
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
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 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
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