// JavaScript is interpreted top to bottom, so any code in this file will be run // as soon as it's loaded into a browser. Functions can be defined along the way as well. // For this lab, we'll work in JS Bin, so you can just paste this into the JavaScript // pane, open the Console pane and click "Run". You can save your work by just pasting // back-and-forth into some file. console.log("This is how you print to the console!"); // The JavaScript console doesn't support user input - we'll be working with content on // web pages. For these exercises, we'll just assign hardcoded values to variables. Note // the point is that the code must work with any values you choose! // Q1: Declare two variables and set them to floating-point values. // Display (on the console) the product of the two variables. // Q2: Declare four variables and set them to floating-point values. // Calculate the average of those variables and display it. // Q3: Declare two variables and set them to string values. // If the two strings are the same, display "Equal". // If the two strings are not the same, display "Not Equal". // Q4: Declare a variable and set it to an integer value. // Determine whether the variable is even or odd, and display "Even" or "Odd". // Q5: Write a function that takes two variables and returns the value of the larger one. // Using that function and the four variables from Q2, display the value of the largest one. // Q6: Declare an array of five integer values. // Using a loop, calculate and display their sum and average. // Q7: Write a function that takes an integer N and uses a loop to display all the positive // integers up to N. // Call that function with the value 8 to display "1 2 3 4 5 6 7 8". // (note! do it on one line using string concatenation) // Q8: Using nested loops, and the variable from Q4, display that many rows of numbers. // The first row should have 1, the second row should have 1 2, third row should have 1 2 3 // and so on. // e.g. Input: 4 // Display: 1 // 1 2 // 1 2 3 // 1 2 3 4 // Q9: Using the array forEach method, display the numbers in the array from Q6. // Q10: Write a function that takes an array of numbers and returns the smallest value. // Call that function with the array from Q6 and display the returned value. // Q11: Declare an associative array with three names as keys and ages as values. // Display all the key/value pairs like: "Jose is 17".