Fundamentals Flashcards
Adds items to the end of an array
Item.push
Removes items from the end of an array
Item.pop
Adds items to the beginning of an array
Item.unshift
Removes the first item from an array if you don’t specify
Item.shift
How do you get today’s date information?
new Date()
This returns DOW, M, D, Y, Time, Time Zone (Time Zone Name)
How to return the numeric value of the current day of the week?
today.getDay()
It will return a 0-6, with the week starting on Sunday at 0.
How to find the current hour of the day?
today.getHours()
Returns the numeric value of a 12-hour clock
How to find the current minute?
today.getMinutes()
Returns the current minute(s) of the current hour from 1-59.
How to get the current second(s) of the day.
today.getSeconds()
Returns the current second(s) from 1-59 of the current minute.
How to find the current date of the day in a month?
today.getDate()
Returns a value between 1-31
How to find the current month of the year?
today.getMonth();
Returns a value between 0-11 for months January through December.
*Will need to add a + 1 to the end to have it equal 1-12
How to find the current year?
today.getFullYear();
Returns the full year in a 4-digit numeric
How to get a random number?
Math.random() will give you a random number from 0 to 1. This includes decimals. If you want it to go higher, multiply it by a number (like “random()*20”) however it will only go from 0-19 in that case, so you should add a +1 at the end.
How to get a random number between 1-20?
Math.trunc(Math.random()*20)+1)
Math.trunc will remove the decimals (it will truncate the number).
The global object of JavaScript in the browser?
Type “window” in the console
Should we ever use “var”?
No. Always use “const” or “let”
Where should variables and functions be defined?
Variables should always be defined at the top of your code.
Functions should be declared next.
What is a “boolean”?
A boolean is a true or false statement (or truthy and falsey)
How do we multiply something by itself multiple times?
**
Multiply multiply take the original item and multiplies it by itself but only when a number is added to the end (like squared or cubed). For example if we wanted 2 to the power of 4, it would be:
2 ** 4 = 16
How can we round a value to the nearest integer?
Math.round()
If we wanted to take a number with multiple decimal points and round it (up or down; whatever is closest) we simply add this bit to the front and put the value in the parenthesis.
Math.round(7.6432456) will simply round to 7.
If it’s a string with a value, it’ll do the same:
const markBMI = 7.6432456
Math.round(markBMI)
markBMI = 7
T/F: an “else if” statement needs to end with an else?
False
T/F: ‘18’ = = = 18
False.
Strict equality has no type coercion.
T/F: ‘18’ = = 18
True
Loose equality has type coercion.
T/F: ‘18’ = 18
False.
“Invalid left-hand side in assignment”
do?