Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript Assignment 3 Create an array called ages that contains the following values:3, 9, 23, 64, 2, 8, 28, 93. Programmatically subtract the value of

JavaScript Assignment 3

  1. Create an array called ages that contains the following values:3, 9, 23, 64, 2, 8, 28, 93.

    1. Programmatically subtract the value of the first element in thearray from the value in the last element of the array (do not usenumbers to reference the last element, find it programmatically,ages[7] – ages[0] is not allowed). Print the result to theconsole.

    2. Add a new age to your array and repeat the step above to ensureit is dynamic (works for arrays of different lengths).

    3. Use a loop to iterate through the array and calculate theaverage age. Print the result to the console.

  2. Create an array called names that contains the following values:‘Sam’, ‘Tommy’, ‘Tim’, ‘Sally’, ‘Buck’, ‘Bob’.

    1. Use a loop to iterate through the array and calculate theaverage number of letters per name. Print the result to theconsole.

    2. Use a loop to iterate through the array again and concatenateall the names together, separated by spaces, and print the resultto the console.

  3. How do you access the last element of any array?

  4. How do you access the first element of any array?

  5. Create a new array called nameLengths. Write a loop to iterateover the previously created names array and add the length of eachname to the nameLengths array.

  6. Write a loop to iterate over the nameLengths array and calculatethe sum of all the elements in the array. Print the result to theconsole.

  7. Write a function that takes two parameters, word and n, asarguments and returns the word concatenated to itself n number oftimes. (i.e. if I pass in ‘Hello’ and 3, I would expect thefunction to return ‘HelloHelloHello’).

  8. Write a function that takes two parameters, firstName andlastName, and returns a full name (the full name should be thefirst and the last name separated by a space).

  9. Write a function that takes an array of numbers and returns trueif the sum of all the numbers in the array is greater than 100.

  10. Write a function that takes an array of numbers and returns theaverage of all the elements in the array.

  11. Write a function that takes two arrays of numbers and returnstrue if the average of the elements in the first array is greaterthan the average of the elements in the second array.

  12. Write a function called willBuyDrink that takes a booleanisHotOutside, and a number moneyInPocket, and returns true if it ishot outside and if moneyInPocket is greater than 10.50.

  13. Create a function of your own that solves a problem. Incomments, write what the function does and why you created it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions