M1D4: JavaScript

Variables

Activity

  1. Declare a new variable named petDog and give it the name Rex.
  2. Declare a new variable named petCat and give it the name Pepper.
  3. Console.log the petDog variable.
  4. Console.log the petCat variable.
  5. Console.log the text “My pet dog’s name is: “ and the petDog variable.
  6. Console.log the text “My pet cat’s name is: “ and the petCat variable.
  7. Declare another variable and name it catSound. Assign the string of “purr” to it.
  8. Declare another variable and name it dogSound. Assign the string of “woof” to it.
  9. Console.log the variable petDog, then the string “says”, then the variable dogSound.
  10. Console.log the variable petCat, then the string “says”, then the variable catSound.
  11. Reassign the value stored in catSound to the string “meow”.
  12. Console.log the variable petCat, then the string “now says”, then the variable catSound.

My Solution

var petDog = "Rex";
var petCat = "Pepper";

console.log(petDog);
console.log(petCat);
console.log("My pet dog's name is: " + petDog);
console.log("My pet cat's name is: " + petCat);

var catSound = "purr";
var dogSound = "woof";

console.log(petDog + " says " + dogSound);
console.log(petCat + " says " + catSound);

catSound = "meow"

console.log(petCat + " now says " + catSound);

Data Types

  • String – text
  • Number – numerical data
  • Boolean – true or false (yes or no)
  • Null – absence of value
  • Undefined – unassigned value (variable)
  • BigInt – very large numbers
  • Symbol – unique identifier

Assignment Operators

+ – * /

Comparison Operators

> Greater than

< Less than

== Equal to

!= Not equal to

Logical Operators

&& Check for both conditions to be true

|| Checks for at least one condition to be true

! Returns false if the result is true

Operators control the flow of a program that meets certain criteria.

Number Data Type

Foundational data type that represents integers and decimal points.

Exponential

10**2 returns 100 (10*10)

Remainder

9%8 returns 1 (remainder is 1)

16%8 returns 0 (16 is divisible by 8, no remainder)

JavaScript follows PEMDAS (parentheses, exponents, multiplication, division, addition, and subtraction)

Strings

A collection of characters enclosed in single quotes or double quotes.

Booleans

!==
===
These are strict equality – checks the value and the type.

This entry was posted in Study Notes and tagged , . Bookmark the permalink.

Leave a Reply