Skip to content

Instantly share code, notes, and snippets.

function doMyLaundry() {
alert("Nice try!");
}
doMyLaudry();
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
}
}
// 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!");
}
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")
}
@natafaye
natafaye / converting-to-arrow-functions.js
Created July 14, 2021 00:58
Javascript Week 4 Code From Class
/*************** 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";
class Animal {
constructor(type, name) {
this.type = type;
this.name = name;
this.votes = 0;
}
// Method using arrow function syntax
toString = () => this.name + " (" + this.type + ")";
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);
<!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>
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 {
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) {