// Number
const count = 5;
// string
let dayOfWeek = "Tuesday";
// function
const updateButtonEvent = () => {
console.log("button clicked")
}
oh look, a detour!
const rollDice = () => {
const randomNumber = Math.ceil(Math.random() * 6)
document
.querySelector(".result")
.textContent = randomNumber
}
document
.querySelector(".d6")
.addEventListener("click", rollDice)
const getRandomNumber = () => {
return Math.ceil(Math.random() * 6)
}
const rollDice = () => {
const randomNumber = getRandomNumber()
document
.querySelector(".result")
.textContent = randomNumber
}
document
.querySelector(".d6")
.addEventListener("click", rollDice)
const needCoffee = true;
const hungry = false;
const needCoffee = true
if (needCoffee) {
refillCoffee()
} else {
getWorkDone()
}
relax()
const numberOfRedCrayons = 10;
const numberOfBlueCrayons = 7;
numberOfRedCrayons > numberOfBlueCrayons // true
numberOfRedCrayons >= numberOfBlueCrayons // true
numberOfRedCrayons < numberOfBlueCrayons // false
numberOfRedCrayons <= numberOfBlueCrayons // false
const scoreString = "10"
const currentScore = 10
const target = 15
currentScore == target // false
currentScore === target // false
currentScore == scoreString // true
currentScore === scoreString //false
const animal = getMySpiritAnimal()
let habitat = "the city"
if (animal === "ox"){
habitat = "the farm"
}
const animal = getMySpiritAnimal()
let habitat = "the city"
if (animal === "ox"){
habitat = "the farm"
} else {
habitat = "woods"
}
const animal = getMySpiritAnimal()
let habitat = "the city"
if (animal === "ox"){
habitat = "the farm"
} else if (animal === "moose"){
habitat = "tundra"
} else {
habitat = "woods"
}
const animal = getMySpiritAnimal()
let habitat = "the city"
if (animal === "ox"){
habitat = "the farm"
} else if (animal === "moose"){
habitat = "tundra"
} else if (animal === "otter"){
habitat = "river"
} else if (animal === "sea tutle"){
habitat = "sea"
} else {
habitat = "woods"
}
const niceOutside = sunny && notTooHot;
const shouldIwatchAMovie = GoodMovie || Raining;
const isNight= !isDay;
don't be scared, might get a bit math-y
A | B | Result |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | F |
A && B
A | B | Result |
---|---|---|
T | T | T |
T | F | T |
F | T | T |
F | F | F |
A || B
const ringsToDestroy = getNumberOfRingsToDestroy()
const ringBearer = getCurrentRingBearer()
if (ringsToDestroy > 0 && ringBearer === "Frodo"){
keepWalking()
} else if (ringsToDestroy === 0){
relaxInTheShire()
} else if (ringBearer !== "Frodo") {
findTheRing()
}
truthy:
- non-zero number
- any string
- anything that is not falsy
falsy:
- false
- 0
- undefined
- null
- NaN
- ''
- ""
// add class/style
const element = document.querySelector("#mySection");
element.classList.add("red-text");
// remove
element.classList.remove("blue-text");