Title: Javascript Practice
Type: Homework
Duration: "3:00 - 4:00"
Creator:
Original creators: WDI-BLT, WDI-Meeskeeks, WDIR-Panthalassa
Adapted by: Kristyn Bryan
Course: WDIR-Matrix
Competencies: Javascript basics, arrays, and conditionals
Prerequisites: Basic Javascript
Create a file
Make a file inside your `homework` folder for w01d04 called `app.js`.Write your Javascript
Write all of your javascript answers in `app.js`.Test your Javascript
Test your answers in the Chrome Console.Note: If you're having trouble with this, you can run your answers in repl.it which is very much like JSBin. DO NOT do all of your work in repl.it, just test it there. Your work should be in your app.js
file.
Write your non-Javascript answers
Any non-javascript written answers can be made into a comment in your `app.js` file by putting a pound # at the beginning of the line. Or, select the blocks of text and comment them out with this shortcut `command` + `/`.Primitive Methods and Properties
- 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:
"Commit 1 - Answered JS basic conceptual questions"
- 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
firstVariable
into a new variable calledsecondVariable
- change the value of
secondVariable
to a string. - What is the value of
firstVariable
?
- Create a variable called
yourName
and set it equal to your name as a string.
- Write an expression that takes the string "Hello, my name is " and the variable
yourName
so that it returns a new string with them concatenated. (ex: "Hello, my name is Jean Valjean")
Commit 2
π΄ The commit message should read:
"Commit 2 - Completed JS basic exercises"
JS Data Types
- 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:
"Commit 3 - Answered JS data type questions"
- 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
a
to make sure it updated the array.
-
Given the following array
class = ["Matrix", "Zoom", "Github", "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:
"Commit 4 - Completed JS data type exercises"
Primitive Methods and Properties
- 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:
"Commit 5 - Answered JS method & properties questions"
- 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
push
method, 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
unshift
method, add the string"Bob Marley"
to the beginning of the array - using a different method, remove the string from the beginning of the array
- use the reverse method on this array
- using the
Commit 6
π΄ The commit message should read:
"Commit 6 - Completed JS method & properties exercises"
Javascript Operators
- 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:
"Commit 7 - Completed JS operator exercises"
Syntax for `if..else` statements
``` if (condition) { //block of code if condition is true } else { //block of code if none of the condition(s) is true. } ```Complete the `if..else` statement
1. Complete the `if..else` statement to alert `little number` if the number is entered is less than **10**.2. If the number entered is more than 10, alert `big number`.
Note: You can put this in a compiler to check your work:
```
var sizeOfNumber = function () {
// write your code here
}
sizeOfNumber(//enter a number to test here);
```
Commit 8
π΄ The commit message should read:
"Commit 8 - Completed if else exercises"
Syntax for `if...else if...else` statements
``` if (condition) { //block of code if condition is true } else if (condition) { //block of code if condition is true } else { //block of code if none of the condition(s) is true. } ```Complete the `if...else if...else` statement
1. Complete the `if...else if...else` statement to alert `little number` if the number is entered is less than **5**.2. If the number is between 5 and 10, alert `middle number`.
3. If the number entered is more than 10, alert `big number`.
- Note: You can put this in a compiler to check your work:
var sizeOfNumber = function () {
// write your code here
}
sizeOfNumber(//enter a number to test here);
Commit 9
π΄ The commit message should read:
"Commit 9 - Completed if else if else else exercises"