Question
Hi. I would appreciate some help over this JAVA SCRIPT assignment. Here are the instructions: Part 1: Arrays -------------- 1. Creating a variable named 'numberArray'
Hi. I would appreciate some help over this JAVA SCRIPT assignment. Here are the instructions:
Part 1: Arrays --------------
1. Creating a variable named 'numberArray' and assign it an array that contains only the numbers 1, 2, 3, 4, 5
2. Reading a(ny) value from the numberArray variable using square bracket notation, and log it to the console
3. Writing a loop that prints each number from the numberArray to the console
If completed correctly, the numbers 1 2 3 4 5 should be logged to the console, one number per line
Part 2: Functions -----------------
4. Creating a function named 'sayHello' that logs the message "Hello!" to the console
5. Writing a loop that runs five times and contains only one statement - a call to your sayHello function If completed correctly, the string "Hello!" will be logged to the console five times, one string per line
6. Creating a function named 'printSomething' that has two parameters (named param1 and param2). The printSomething function should contain *only one* statement - a call to console.log that logs the values of the two parameters
7. Calling the printSomething function, passing in the first two values from your 'numberArray' array
If completed correctly, the numbers 1 and 2 will be printed to the console, both on the same line
Part 3: Objects ---------------
8. Creating a variable named 'testObject' and assign it an object with two properties, "name" and "id". Fill the name and id properties with values of your choosing
9. Calling the printSomething function, passing in the name and id (separately!) of testObject as your two arguments
If completed correctly, the two values assigned to the name and id properties will be printed to the console, both on the same line
Part 4: Combining Arrays, Functions, and Objects ------------------------------------------------
10. Calling the .forEach method on your 'numberArray' array. Inside the function argument that you provide to .forEach, call printSomething, passing the current number from the number array as the first argument, and the name from testObject as your second argument
If completed correctly, the output in the console (assuming, for argument's sake, that the value of the testObject's name property is 'Jason') will look something like: 1 'Jason' 2 'Jason' 3 'Jason' 4 'Jason' 5 'Jason'
Part 5: Written ---------------
Writing responses to the next two questions as comments inside your script, using plain english
11. Explain briefly *at least* two differences between loops and functions
12. Explain briefly *at least* two differences between arrays and objects
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started