So, I am into the javascript section, and I am struggling with the examples in the problems. They seem so nonsensical, and I needed something a little different. I found the following meme on imgur, and I laughed like crazy (yeah…i’m a mom). I also realized, that this meme could be turned into a function. So, I went onto codepen, and fiddled around, and made a working function. It takes two parameters: 1. Is there a cowboy in your room? 2. Is it cowboy times? Based on your true, false answers, it returns a string. The function is not complete, as it doesn’t have the second half of the meme (the part about a horse, and a bad cowboy). My next goal, is to turn this meme into a webpage, with questions, and buttons. You choose the answers to the questions, and the next question pops up… I really needed something that tied together HTML, CSS, and javascript (that didn’t involve complex math calculations, or at least some that made sense like the return random phrase).
function cowboyinmyroom(cowboy, cowboyTimes) {
if(cowboy === true && cowboyTimes === true) {
console.log(“Go back to bed”);
}else if (cowboy === true && cowboyTimes === false) {
var answer = [
“Why are you here, cowboy?”,
“Cowboy, why are you here?”
]
var randomPhrase = answer[Math.floor(Math.random() * answer.length)];
console.log(randomPhrase);
}else if (cowboy === false && cowboyTimes === true){
console.log(“You have somehow gone back in time. Find Doc”);
}else {
console.log(“There is neither a cowboy, or a time warp. You had a nightmare, go back to sleep”);
}
}
cowboyinmyroom(true, false);