- Gain practice coding proper syntax for Javascript data types
- Gain experience with Git: add and commit your code frequently.
- Feel comfortable searching through and using MDN's Documentation.
- Access and change values for Javascript data types (String, Array, Objects)
- In today's
homework
folder, touch ascript.js
file. - Open the file by typing
atom script.js
in terminal. - You will write your Javascript in here. You can run and test your code in the terminal by running
node script.js
.
- Get through all the challenges and be crowned Javascript Ninja Warrior.
- You can comment out code you're not using with the shortcut
cmd
+/
. - Each instruction's code should go on its own line.
- You need to test your variables, even if there is no instruction to console log them. Make sure you're logging the right value by leaving all other console logs commented out to avoid mega confusion down the road.
- Half the struggle with programming is dealing with syntax errors. Since coding is about writing a specific set of instructions, it's important to pay extra attention to your code: capitalization, lower case, correct symbols, quotes, semi-colons, etc... it matters. If you're not seeing the answer as you expect or you get a syntax error.. double check your syntax, character by character.
- Create a variable
a
and set it equal totrue
. - Create a variable
b
and set it equal tofalse
. - Write a statement using
a
andb
that evaluates tofalse
.
- console log the result to terminal
- Write a statement using
a
andb
that evaluates totrue
.
- console log the result to terminal
For each expression below, indicate whether it is 'truthy' or 'falsey' by assigning a variable a value of either true or false:
- true && false
- true && 1 != 1
- "1" === 1
- !(true && false)
- false || 0 != 0
- 3 >= 3 && (!("banana" === "banana" || "javascript" === "fun"))
- null === undefined
- isNaN(undefined)
- 🎯 Commit -m "Commit 1: Boolean Skills"
Refer to the MDN Docs about Math
.
- Create a variable
d
and set it equal to a10
. - Create a variable
e
and set it equal to13.445
. - Console log the difference.
- In the next line, set
e
equal toInfinity
. - Console log the difference.
- Using Math.min, create a variable called
minNumber
and set it equal to the smaller value betweend
ande
. - Using Math, create a variable called
superPower
, set it equal to9000 to the power of one-half
. - Using Math, create a variable called
randomNum
and set it equal to a random number rounded down between 1 and 10. - Console log the result of
randomNum
and make sure there are no decimals. - 🎯 Commit -m "Commit 2: Number Skills"
Refer to the String methods listed in MDN Docs
- Create a variable called
myName
and set it equal to your first name. - Create a variable called
myFavoriteThing
and set it equal to"long walks on the beach."
- Create a variable called
myQuote
. Using string interpolation, usemyName
andmyFavoriteThing
to output "Hi, my name is Christine and I like long walks on the beach." Except it should say your name, not Christine. Mind the spacing! - Using a different string interpolation method (string literals?), console log the exact same output.
- Create a variable called
number
and set it equal to10
. - Create a variable called
doesItWork
and set it equal tomyName + number
. Console log it. Is it what you expected? - Create a variable called
thirdCharacter
and set it equal to the third character inmyName
. Console loggingthirdCharacter
should give you back only the 3rd letter in your name. - Create a variable called
secondWord
. Using slice onmyFavoriteThing
, setsecondWord
equal to the string"walks"
(no spaces).
var secondWord = "walks"
does not count.
- 🎯 Commit -m "Commit 3: String Skills"
- Create a variable
coolArray
and set it equal to an empty array. - Set the variable
coolArray
to an array with 3 Strings and 3 Numbers. - Console log the last element of the array.
- Set the second value of
coolArray
to the string"Nunchuck Skills"
. - Set the third value of
coolArray
to the Number 100. - Push the Boolean value
true
intocoolArray
. - Console log the data type of the third element of the array.
- Console log
coolArray
. Does it reflect all the above changes? - 🎯 Commit -m "Commit 4: Array Skills"
Add the following object to script.js
and write code to access/change the properties for the heart
object:
var heart = {
bpm : 140,
increaseBpm : function(value) {
this.bpm += value;
}
}
- Create a variable called
bpm
and set it equal to heart's bpm value.
var bpm = 140
does NOT count! Access140
some how.
- Set heart's bpm to
120
. - Write a new function within the heart object that will decrease bpm by a value of the user's choosing.
- Invoke the increaseBpm function and the decreaseBpm function and console.log the results.
- Include a new key in heart object called 'color', and set the value to "red".
- Make a function inside the heart object that changes the color to a value of the user's choosing.
- Invoke the color function and set the color to 'black', and console.log the color.
- 🎯 Commit -m "Commit 5: Object Skills"
You're almost done! You've had a good warm up with Javascript basics. Now let's solidify your knowledge with the ALL concepts you've learned so far.
Answer the questions in script.js
in the form of a comment (short answers).
- List at least 5 properties built into a string.
- What does running
git status
do? - In your own words, what is type coercion in Javascript?
- What is the difference between == and === ?
- What command line shortcut lets me see what directory I'm currently in?
- What's the difference between forking and cloning in Github?
- What's the difference between a
while
loop and ado while
loop? - 🎯 Commit -m "Commit 6: Object Skills"
Reach Goals are not required for homework completion, but I highly recommend you try to master them all! Sharpen those skills!
- Write a
for
loop that counts from 0 (inclusive) to 1857 (exclusive) and calculates the sum of all of those numbers, storing the result in the variablereachGoalOne
.
- 🎯 Commit -m "Commit 7: Reach 1 Done"
- Write a
while
loop that increasescount
by 12 when it's strictly below 95, decreases it by 7 when it's strictly above 105, and stops as soon ascount
equals or falls between those two values.
- 🎯 Commit -m "Commit 8: Reach 2 Done"
- Using whatever code you like, calculate n^n for each value from n from 1 to 10 (both inclusive), and store the sum in the variable
reachGoalThree
.
- 🎯 Commit -m "Commit 9: No one can defeat me!"
When you're ready, create an issue on the class repo with a title in the format "First and Last Name -- Week XX Day XX". The issue body should have:
- A link to your forked repo (ie. to your
homework
folder) - A 'comfort' score on how you feel about your answers, from 1 (very uncomfortable) to 5 (very comfortable)
- A 'completeness' score, from 1 (didn't do it) to 5 (finished all of it)
- A 'win'
- A 'struggle'
- A 'comment'