Printing those products!


  1. Below the // number 1 comment are a number of strings, each one containing a product name and price separated by a colon. We'd like you to turn this into an array and store it in an array called products.
  2. On the same line as the // number 2 comment is the beginning of a "for loop". In this line we currently have i <= 0, which is a conditional test that causes the "for loop" to only run once, because it is saying "stop when i is no longer less than or equal to 0", and i starts a 0. We'd like you to replace this with a conditional test that stops the loop when i is no longer less than the products array's length.
    For an additional hint, if you were to add + 1, or - 1 following the requested code, it will add or subtract a line in the list respectively. Give it a try.
  3. Just below the // number 3 comment we want you to write line(s) of code that splits the current array item (name:price) into two separate items, one containing just the name and one containing just the price.
  4. As part of the above line(s) of code, you'll also need to convert the price from a string to a number.
  5. There is a variable called total that is created and given a value of 0 at the top of the code. Inside the loop (below // number 4) we want you to add a line that adds the current item price to that total in each iteration of the loop, so that at the end of the code the correct total is printed onto the invoice. You might need an assignment operator to do this. Hint: It's a simple short line of code.
  6. Change the line just below // number 5 so that the vairable is made equal to "current item name - $current item price", for example "Shoes - $23.99" in each case, so the correct information for each item is printed on the invoice. This is just simple string concatenation, which should be familiar to you. For additional thought, after you inserted this code, try replacing it with products just to see what happens!