Functions

For these exercises, always return the answer!

function adder(first, second) {
  let theAnswer = first + second;
  return theAnswer;
}

Relational Operators

Symbol Meaning
=== exactly equals
!== does not equal
= assignment
+= add or concatenate
-= subtract
* multiplication
/ division
% remainder (modulo)
> greater than
>= greater than or equal
< less than
<= less than or equal

Logical Operators

Symbol Meaning
! not
&& and
|| or

If / Else If / Else

let someNumber = prompt("Pick a number");

if (someNumber < 42) {
  // something
}
else if (someNumber === 42) {
  // another thing
}
else {
  // some default action
}

While Loop

let number = 0;
while (number < 5) {
  console.log(number);
  number = number + 1;
}

// 0
// 1
// 2
// 3
// 4

For Loop

for (let number = 5; number > 0; number -= 1) {
  console.log(number);
}
console.log("Blastoff!");

// 5
// 4
// 3
// 2
// 1
// Blastoff!

Arrays

let nums = [42, 13, 78];
nums[0];  // 42
nums[2];  // 78
nums.length;  // 3

nums.push(99);
// now nums = [42, 13, 78, 99]

let last = nums.pop();
// now last = 99 and nums = [42, 13, 78]

let first = nums.shift();
// now first = 42 and nums = [13, 78]

nums.unshift(55);
// now nums = [55, 13, 78]

Math Functions

let nearestInt = Math.round(1.55); // nearestInt is now 2
let nextLowestInt = Math.floor(1.55); // nextLowestInt is now 1
let nextHighestInt = Math.ceil(1.2); //nextHighestInt is now 2