Skip to content

Instantly share code, notes, and snippets.

@kristynrb
Created November 3, 2016 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristynrb/6754f7f4260574f2935ccea69dc18ba1 to your computer and use it in GitHub Desktop.
Save kristynrb/6754f7f4260574f2935ccea69dc18ba1 to your computer and use it in GitHub Desktop.
Homework for w01d04

ga

WDIR-MATRIX


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


Homework

js

Setup

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` + `/`.

Javascript Basics

Primitive Methods and Properties

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?

Commit 1


πŸ”΄ The commit message should read:
"Commit 1 - Answered JS basic conceptual questions"

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?
  1. 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"

Javascript Data Types (Primitives)

JS Data Types

Conceptual Questions

  1. Name 4 different built in data types (primitives) in Javascript.
  2. What is the difference between an integer and a float?
  3. 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"

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.
  1. 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.
  2. Create a string that contains quotes and store it in a variable.

  3. What is the result from the expression "World" * 5. Why?

Commit 4


πŸ”΄ The commit message should read:
"Commit 4 - Completed JS data type exercises"

JavaScript - Primitive Methods & Properties

Primitive Methods and Properties

Conceptual Questions

  1. List at least 5 properties built into a string.
  2. List at least 2 method examples built into an array.

Commit 5


πŸ”΄ The commit message should read:
"Commit 5 - Answered JS method & properties questions"

Exercises

String

  1. Given the following string "The Peculiar Purple Pieman of Porcupine Peak"
    • How can we check the length of this string?

Array

  1. 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

Commit 6


πŸ”΄ The commit message should read:
"Commit 6 - Completed JS method & properties exercises"

Javascript - operators

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"

Conditionals

If else

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"

If, else if, else

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"

When You're Done

Hungry for more? - Finish your lab from today! https://github.com/ga-students/wdi-remote-matrix/blob/master/unit_1/w1d4/student_labs/LAB_pick_a_path.md
Submission - Inside this folder (w01d04/homework), you should now have a file called `app.js`. - You should have been adding and committing along the way, but please type `git status` one last time to make sure that everything is commited. If it's not, please commit. - Push your work to your github repo `git push origin master` - Follow the instructions for submitting homework, found in [the wiki](https://github.com/ga-students/wdi-remote-matrix/wiki/Homework-Submission)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment