4.4 KiB
WDI-PANTHALASSA
Title: Javascript Homework for w01d04
Type: Homework
Duration: "2:00"
Creator:
Original creators: WDI-BLT, WDI-Meeskeeks
Adapted by: Kristyn Bryan
Course: WDIr Panthalassa
Competencies: Javascript
Prerequisites: Basic Javascript
Homework - Javascript Basics
Setup
Make a file inside your homework folder for w01d04 called app.js. Write all of your javascript answers in app.js, and test them in the bash console using the command node app.js from inside the homework folder.
Any non-javascript written answers can be made into a comment in your .js file by putting a pound # at the beginning of the line. Or, if you write a comment, you can select the blocks of text and comment them out with this shortcut command + /.
Conceptual Questions
- How do we assign a value to a variable?
- How do we change the value of a variable?
- How do we assign an existing variable to a new variable?
- How do we use a variable within an expression?
Commit 1
The commit message should read:
"Answered JS basic conceptual questions"
Exercises
- Create a variable called
firstVariable.
- assign it the value of a string =>
"Hello World" - change the value of this variable to a number.
- store the value of
firstVariableinto a new variable calledsecondVariable - change the value of
secondVariableto a string. - What is the value of
firstVariable?
- Create a variable called
yourNameand set it equal to your name as a string.
- Write an expression that takes the string "Hello, my name is " and the variable
yourNameso that it returns a new string with them concatenated. (ex: "Hello, my name is Jean Valjean")
Commit 2
The commit message should read:
"Completed JS basic exercises"
...
Javascript Data Types (Primitives)
Conceptual Questions
- Name 4 different built in data types (primitives) in Javascript.
- What is the difference between an integer and a float?
- How do you create an empty array and store it in a variable?
Commit 3
The commit message should read:
"Answered JS data type questions"
Exercises
- Given the following array
var a = [1, 10, "Hello", true]
- how do you access the 1st element in the array?
- Change the value of
"Hello"to"World". - Check the value of
ato make sure it updated the array.
-
Given the following array
["Panthalassa", "Zoom", "Cloud9", "Github"]- What would you write to access the 3rd element of the array?
- Change the value of "Github" to "Octocat"
- Add a new element, "Cloud City" to the array.
-
Create a string that contains quotes and store it in a variable.
-
What is the result from the expression
"World" * 5. Why?
Commit 4
The commit message should read:
"Completed JS data type exercises"
JavaScript - Primitive Methods & Properties
Conceptual Questions
- List at least 5 properties built into a string.
- List at least 2 method examples built into an array.
Commit 5
The commit message should read:
"Answered JS method & properties questions"
Exercises
-
Given the following string
"The Peculiar Purple Pieman of Porcupine Peak"- How can we check the length of this string?
-
Given the following array
[5,10,500,20]- using the
pushmethod, add the string"Egon"to the end of the array. - using a different method, remove the string from the end of the array.
- using the
unshiftmethod, add the string"Bob Marley"to the beginning of the array - using a different method, remove the string from the beginning of the array
- using the
Commit 6
The commit message should read:
"Completed JS method & properties exercises"
...
Javascript - operators
Exercises
1.
Using the provided variable definitions, replace the blanks with a mathematical or boolean operator that evaluates the expression to true. 👋
var a = 4;
var b = 53;
var c = 57;
var d = 16;
var e = 'Kevin';
- a _ b;
- c _ d;
- 'Name' ___ 'Name';
- a _ b ___ c;
- a _ a ___ d;
- e ___ 'Kevin';
- 48 ___ '48';
...
Commit 7
The commit message should read:
"Completed JS operator exercises"
