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:

Module Notes

Animated Circles overview

Opening the Console:


Javascript Demo: Lesson 1

With the demo file today are examples of short scripts that demonstrate basic uses of values, data types, operators and conditionals. You follow by also uncommenting the commented out script. Make sure comment again before moving to the next.

After this you will open up a new HTML page to try out your own use of these scripts. In Sublime Text, save a new HTML file and then type "html" & press the tab key to generate boilerplate. Save in a "DTC 477" folder for future reference.

Values, Types and Operators

W3Schools Tutorials


WORKSHOP

Challenge 1: Personal Greeting

Ask the viewer for their name using a prompt.

Store the name in a variable and display a greeting that includes their name.

Example output:
Hello Alex, welcome to the page!

Challenge 2: Age Calculator

Ask the viewer for their age.

Convert the string input to a number (parsInt("10")), then calculate how old they will be in 10 years.

Display both their current age and their age in 10 years.

Example output:
You are 19 years old. In 10 years, you will be 29.

Challenge 3: Yes / No Decision

Ask the viewer a yes/no question using a confirm box.

Use an if / else statement to display a different message depending on their answer.

Example:
Do you like movies?

Challenge 4: Name Inspector

Ask the user for their name using a prompt. Display:

Challenge 5: Favorite Foods List

Create an array with three of your favorite foods (strings). Display:

Hint: the last item uses array.length - 1.


Rock Paper Scissors Game Steps

  1. Ask the user to enter either "rock", "paper", or "scissors".
  2. Save the user’s choice in a variable.
  3. Create a list (array) of possible choices: "rock", "paper", "scissors".
  4. Have the computer randomly pick one option from that list.
  5. Save the computer’s choice in another variable.
  6. Print (or log) both the user’s choice and the computer’s choice so they are visible.
  7. 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.
  8. Print the outcome: "User wins", "Computer wins", or "Tie".
>

Project 1: Interactive Website (5%)

This assignment brings together syntax, variables, conditionals, arrays, functions, and loops in JavaScript. Create a dynamic website with user interaction that changes content on the page.

Suggested Ideas:
Working with ChatGPT:
  1. Describe your idea and layout for HTML structure.
  2. Detail your JavaScript steps in plain language.
  3. Start coding with ChatGPT’s guidance.
  4. Iteratively refine and troubleshoot.