JSFiddle - React, Tailwind, and code Playground

by Jennifer Piccione

JavaScript

/**
 * Exercise:
 * Get to know your data types and variables
 *
 * Follow the directions below but feel free to experiment and veer off course.
 * Work in the console, or use "console.log()" to output to the console from the script.
 */

console.clear();

// 1)
// Declare 2 to 5 variables (name them as you like)
// Make at least one string, one number and one boolean. 
// Log the typeof each to the console

var a = 1; 
var b = "hello"; 
var c = false;
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);

// 2)
// Declare a new variable that stores the result of a mathematical expression
// You can add/multiply/divice/modulo any set of numbers 
// Log the result to the console

var mathVar = 1 + 2;
console.log(mathVar);

// 3)
// Combine at least three strings together
// Log the result to the console

var str1 = "My ";
var str2 = "name ";
var str3 = "is Jenny";
var str4 = str1 + str2 + str3;
console.log(str4);

// 4)
// Create an array with at least 5 values stored inside
// Log the result to the console

var myArray = [1,2,3,4,5];
console.log(myArray);

// 5)
// Add another array to your original array
// Log the result to the console

var myArray2 = [6,7,8,9];
var myArray3 = myArray + myArray2;
console.log(myArray3);

// 6) 
// Create an object literal that represents a person (perhaps you!)
// Define several properties within the object (name, hairColor, age, etc..)
// Define a property that stores an array ("siblings" or "favoriteColors")
// Log the result to the console
// Log ONLY the "name" property (or any single property) to the console
// Change the "name" property to something else, then log the object to the console

var personObject = {
    name: "Jenny",
    hairColor: "brown",
    age: 24,
    siblings: ["Angela", "Stephanie"]
};
console.log(personObject);
console.log(personObject.name);
personObject.name = "Jennifer";
console.log(personObject.name);

// 7) Bonus
// Add a function (method) to the previous person object you created...