Exercise – Variables & Data Types

by jordwms

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 directly OR use "console.log()" to output to the console from the script.
 */

// 1)
// Declare 2 to 5 variables (name them as you like)
var a, b, c, d, isFun;
// Make at least one string, one number and one boolean. 
a = "This is fun!";
b = '1';
c = b;
d = b + c;
isFun = true;

// Log the typeof each to the console
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);
console.log(typeof d);
console.log(typeof isFun);

// 2)
// Declare a new variable that stores the result of a mathematical expression
var x;
// You can add/multiply/divide/modulo any set of numbers 
x = 3 % 2;
// Log the result to the console
console.log(x);

// 3)
// Combine at least three strings together
// Log the result to the console
console.log(a,'I for', b, ', think so!' );

// 4)
// Create an array with at least 5 values stored inside
var fiveElementsArr = [0,1,2,3,4];
// Log the result to the console
console.table(fiveElementsArr);

// 5)
// Use Array.prototype.concat to add another array to your original array
// e.g. var arr3 = arr1.concat(arr2);
var twoElementsArr   = [5,6];
var sevenElementsArr = fiveElementsArr.concat(twoElementsArr);

// Log the result to the console
console.table(sevenElementsArr);

// 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")
var person = {
	"sex" : "male",
    "hair" : "bald",
    "name" : "Jordan",
    "height" : "5 ft 8 in",
    "siblings" : ["Julia", "Jenni", "Jason"]
};
// Log the object to the console
console.log(person);
// Then Log ONLY the "name" property to the console
console.log(person.name);
// Then Change the "name" property to something else, then log the object to the console
person.name =...