Exercise – Operators & Control Structures

by manu troiani

JavaScript

/**
 * Exercise:
 *
 * Get to know your control structures
 *
 * Work in the console, or use "console.log()" to output to the console from the script
 *
 * these browser based functions can be used
 *     alert("Message string"); // will alert a message to the user
 *     var val = prompt("Question string?"); // will prompt the user for a value and return the value
 *     confirm("Message string"); // will ask the user to confirm with an ok, or cancel, returning a boolean
 */
/**
 * 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)
// Make at least one string, one number and one boolean. 
// Log the typeof each to the console

var mynumber = 100;
var mySecondNumber = 9999999999999999;

var mystring = "abc";
var isboolean = true;

typeof mynumber;
typeof mystring;
typeof isboolean;

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

var sum_result = mynumber + mySecondNumber;
console.log(sum_result); 
var divide_result =    mySecondNumber / mynumber;
console.log(divide_result); 
var multiply_result = mynumber * mySecondNumber;
console.log(multiply_result); 
var moduleThree = mynumber % 3;
console.log(moduleThree); //1
var moduleFive = mynumber % 5; //0



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

console.log( "100" + 40);


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

console.log( ["100" , 40]);
var myArray = ["100" , 40, false];
console.log(myArray);

// 5)
// Use Array.prototype.concat to add another array to your original array
//  var arr3 = arr1.concat(arr2);
// Log the result to the console

var...