# Javascript Basics ![js](http://www.mastergradeit.co.za/files/thumb/289/200) ## Setup Make a folder called `js_basics` inside your homework folder. Inside `js_basics` touch an index.html and an app.js and link them together. Write all of your javascript answers in `app.js`, and test them in the Chrome console. 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. Alternatively, comment out written work by using `command + /` in sublime. You can select blocks of text and comment them out with this shortcut. ## Conceptual Questions 1. How do we assign a value to a variable? 2. How do we change the value of a variable? 3. How do we assign an existing variable to a new variable? 4. How do we use a variable within an expression? ## Exercises 1. 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 called `secondVariable` - change the value of `secondVariable` to a string. - What is the value of `firstVariable`? 2. 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")* ... # Javascript Primitives ## Conceptual Questions 1. Name 4 different built in primitives in Javascript. 2. What is the difference between an integer and a float? 4. How do you create an empty array and store it in a variable? ## Exercises 1. 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. 2. Given the following array `["Meeseeks", "Coldness", "21 Berry", "Venkman"]` - What would you write to access the 3rd element of the array? - Change the value of "Venkman" to "Slimer" - Add a new element, "Cloud City" to the array. 3. Create a string that contains quotes and store it in a variable. 4. What is the result from the expression `"World" * 5`. Why? # JavaScript - Primitive Methods & Properties ## Conceptual Questions 1. List at least 5 properties built into a string. 2. List at least 2 method examples built into an array. ## Exercises 1. Given the following string `"The Peculiar Purple Pieman of Porcupine Peak"` - How can we check the length of this string? 3. 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 ... # Javascript - operators ## Exercises #### 1. Using the provided variable definitions, replace the blanks with a mathematical or boolean operator that evaluates the expression to true. :wave: ``` 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'; ...