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 doMyLaundry() { | |
alert("Nice try!"); | |
} | |
doMyLaudry(); |
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 fillBasket() { | |
emptyBasket(); | |
// Replace NUMBER_OF_TIMES with how many times you want your loop to loop | |
for(let i = 0; i < NUMBER_OF_TIMES; i++) { | |
// The code to run over and over again | |
} | |
} |
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
// Bitter Magic 8-Ball | |
let question = prompt("What's your question?"); | |
let firstName = prompt("What's your name?"); | |
if(question === null) { | |
if(firstName === "Bob") { | |
alert("Have a great day!"); | |
} |
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 getAnimalListString(animals) { | |
// We can do this with reduce or map & join | |
// return animals.reduce(function(animalListString, animal) { | |
// return animalListString + "\n" + animal.name + " (" + animal.type + ")"; | |
// }, "Here are the animals:"); | |
return "Here are the animals:\n" + animals.map(function(animal) { | |
return animal.name + " (" + animal.type + ")"; | |
}).join("\n") | |
} |
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
/*************** Is Yes No ***************/ | |
// The original function | |
function isYesNo(answer) { | |
return answer.toLowerCase() === "yes" || answer.toLowerCase() === "no"; | |
} | |
// Converted into a one line arrow function | |
const isYesNo = (answer) => answer.toLowerCase() === "yes" || answer.toLowerCase() === "no"; |
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
class Animal { | |
constructor(type, name) { | |
this.type = type; | |
this.name = name; | |
this.votes = 0; | |
} | |
// Method using arrow function syntax | |
toString = () => this.name + " (" + this.type + ")"; |
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
const expect = chai.expect; | |
describe('QuestionPrompt', function() { | |
describe('constructor', function() { | |
it('should set up the properties correctly', function() { | |
let question = "Question?"; | |
let acceptedAnswers = ["accepted", "answers"]; | |
let qPrompt = new QuestionPrompt(question, acceptedAnswers) | |
expect(qPrompt.question).to.be.a('string'); | |
expect(qPrompt.question).to.equal(question); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<nav> |
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
let numCats = prompt("How many cats do you have?"); | |
numCats = parseInt(numCats); // convert the string (ex: "3") to the number (ex: 3) | |
if(numCats < 1) { | |
console.log("You need more cats") | |
} | |
else if(numCats > 10) { | |
console.log("That is tooo many cats") | |
} | |
else { |
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
let number = Math.ceil(Math.random() * 10) | |
alert("The secret number is " + number) // just for testing | |
let gameOn = true | |
while (gameOn) { | |
let guess = prompt("Guess a number between 0 and 10") | |
if (guess === null || guess === "null" || guess === ""){ | |
alert("Game cancelled. Refresh to start again.") | |
gameOn = false | |
} else if (parseInt(guess) === number) { |
OlderNewer