Variables
Activity
- Declare a new variable named petDog and give it the name Rex.
- Declare a new variable named petCat and give it the name Pepper.
- Console.log the petDog variable.
- Console.log the petCat variable.
- Console.log the text “My pet dog’s name is: “ and the petDog variable.
- Console.log the text “My pet cat’s name is: “ and the petCat variable.
- Declare another variable and name it catSound. Assign the string of “purr” to it.
- Declare another variable and name it dogSound. Assign the string of “woof” to it.
- Console.log the variable petDog, then the string “says”, then the variable dogSound.
- Console.log the variable petCat, then the string “says”, then the variable catSound.
- Reassign the value stored in catSound to the string “meow”.
- 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.
Leave a Reply