Skip to content

Instantly share code, notes, and snippets.

@camckin10
Last active August 10, 2017 01:48
Show Gist options
  • Save camckin10/4d5713e9e88d39f5f65d19bfea88909e to your computer and use it in GitHub Desktop.
Save camckin10/4d5713e9e88d39f5f65d19bfea88909e to your computer and use it in GitHub Desktop.
Event Drills
//Session Questions
//discuss difference between function and event? I am thinking they can be used interchangeably
//event.current.target vs. this
//when the console is not printing anything, what is going on??
//
1. cat carousel
function thumbnailClicks() {
$('.thumbnail').click(function(event){//selecting thumbnail from html,and making an event
var image=$(event.current.target).find('img').attr('src');//creating a variable that will make current target an event.
//searching this image using .find method and .attr method from W3Schools
//question-what comes next?
})
}
//calling function/event to make sure it works.
$function() {
thumbnailClicks();
});
2.FizzBuzz
Fizz Buzz Challenge
//issues? --console not printing anything
var fizzAnswer = 'fizz';//declared a set of global variables
var buzzAnswer = 'buzz';//global variables continued
var fizzBuzzAnswer ='fizzbuzz';//global variables continued
function findFizzBuzzAnswer(number) {//function has one argument in parameter
var result = number;
if(number % 30 === 0) {
result = fizzBuzzAnswer;
} else if (number % 5 === 0) {
result = buzzAnswer;
} else if (number % 3 === 0) {
result = fizzAnswer;
}
return result;
}
//findFizzBuzzAnswer(10);
//Problems: console not printing anything.
//Review how to call a function again?
function printFizzBuzzChallenge (problem) {
var number = 5; //define number for message
var answer = problem;//referring back to argument in function
var message = "this" + "" + problem + "is divisible by" + number;
return answer;//return variable answer to get result?
return message;//telling the computer to return the string in variable
message
}
printFizzBuzzChallenge(10);
3. Lightbulb
function lightbulbClicks() {
$('.lightbulb').click(function(event) {
$('.lightbulb').remove('bulb-on');
$(event.current.target).add('bulb-on')//event.current.target is another way of saying 'this'.
});
}
$(function() {
lightbulbClicks();
});
CORRECT ANSWER
function lightbulbClicks() {
$('.lightbulb').click(function(event) {
$('.lightbulb').removeClass('bulb-on');
$(event.currentTarget).addClass('bulb-on')//event.current.target is another way of saying 'this'.
});
}
$(function() {
lightbulbClicks();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment