Created
September 27, 2020 19:09
-
-
Save lwcooper/e2d347af681440182cea5020305b56e7 to your computer and use it in GitHub Desktop.
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 displayPerson(person, hasFreeCoffee) { | |
const coffeeTableEl = document.getElementById("coffeeTable"); | |
coffeeTableEl.innerHTML = | |
coffeeTableEl.innerHTML + | |
` | |
<tr> | |
<td>${person.name}</td> | |
<td>${person.age}</td> | |
<td>${person.numbersOfCoffees}</td> | |
<td>${hasFreeCoffee ? "Yes" : "No"}</td> | |
</tr> | |
`; | |
} | |
function calculateHasFreeCoffee(person) { | |
let hasFreeCoffee; | |
if (person.age >= 65) { | |
hasFreeCoffee = true; | |
} else if (person.numbersOfCoffees === 10) { | |
hasFreeCoffee = true; | |
} else { | |
hasFreeCoffee = false; | |
} | |
return hasFreeCoffee; | |
} | |
const person1 = { | |
name: "Lyman Hack", | |
age: 34, | |
numbersOfCoffees: 9, | |
}; | |
const person1HasFreeCoffee = calculateHasFreeCoffee(person1); | |
displayPerson(person1, person1HasFreeCoffee); | |
const person2 = { | |
name: "Amber Hernandez", | |
age: 51, | |
numbersOfCoffees: 10, | |
}; | |
const person2HasFreeCoffee = calculateHasFreeCoffee(person2); | |
displayPerson(person2, person2HasFreeCoffee); | |
const person3 = { | |
name: "Herbert Baggett", | |
age: 72, | |
numbersOfCoffees: 4, | |
}; | |
const person3HasFreeCoffee = calculateHasFreeCoffee(person3); | |
displayPerson(person3, person3HasFreeCoffee); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment