Skip to content

Instantly share code, notes, and snippets.

<!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>
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);
class Animal {
constructor(type, name) {
this.type = type;
this.name = name;
this.votes = 0;
}
// Method using arrow function syntax
toString = () => this.name + " (" + this.type + ")";
@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";
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")
}
// 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 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
}
}
function doMyLaundry() {
alert("Nice try!");
}
doMyLaudry();