Week 2: Values, Types & Operators

To Do This Week:

Assignments:

Codecademy: Complete the lessons (not the projects) from the Learn JavaScript module:
  1. "Welcome to Learn JavaScript"
  2. "Introduction to JavaScript", "Variables"
  3. "Conditionals"

Optional Reading:

Read chapters from Eloquent JavaScript:
Super Survey

Javascript Demo: Lesson 1

Opening the Console:

Animated Circles overview

Values, Types and Operators

W3Schools Tutorials


WORKSHOP

Within the JS Demo Lesson 1 are examples of short scripts with very basic uses of values, data types, operators, conditionals and simple arrays. Uncommenting scripts make them active to try. Make sure to comment again before moving to the next.

Using VS Code in this Class

Set Up Your HTML File
Useful VS Code Shortcuts
Annoying Code Suggestions

In-Class Challenges

Below are JS mini-challenges. In a new HTML document, use variables, data types (numbers, strings and booleans), operators, conditionals and arrays to complete them.

Student Pairings Shuffle

Challenge 1: Personal Greeting

Challenge 2: Age Calculator

Note: parseInt() turns a string containing a number into an integer that JavaScript can use for math.

let number = "8";
let integer = parseInt(number);

Challenge 3: Yes / No Decision

Challenge 4: Favorite Movies List — Arrays

Hint: To access the last item, use array.length - 1.


Rock Paper Scissors Game Steps

  1. Ask the user to enter either "rock", "paper", or "scissors". Saved as prompt variable
  2. Create a list (array) of possible choices: "rock", "paper", "scissors".
  3. Have the computer randomly pick one option from that list.
  4. Save the computer’s choice in another variable.
  5. Print (or log) both the user’s choice and the computer’s choice so they are visible.
  6. Compare the two choices:
    • If both choices are the same, declare a Tie.
    • If the user chooses "rock" and the computer chooses "scissors", the user wins.
    • If the user chooses "paper" and the computer chooses "rock", the user wins.
    • If the user chooses "scissors" and the computer chooses "paper", the user wins.
    • In all other cases, the computer wins.
  7. Print the outcome: "User wins", "Computer wins", or "Tie".
>