Once you have mastered defining and looping through an array, have a look at the video to the left for some interesting things you can do with an array.
Create a copy of t09_compound.js and name it t10_array.js
b) Create a program that uses an array to hold the chocolate bar names and calculate the most expensive chocolate bar the user can afford with their pocket money.
As in TASK NINE:
Ask the user how much pocket money they have between $1 and $5.
Check that they have entered a valid number within the range 1 to 5.
Calculate the most expensive chocolate bar the user is able to buy, given how much money they have:
Mars bar - $1, Moro bar - $2, King Size Crunchy - $3, Dairy Milk Block - $4, Lindt Block - $5.
Display a message informing the user the most expensive chocolate bar they could buy.
What is the advantage of using an array over using hard coded values inside an if statement?
Think about how to add new chocolate bars when using the hard coded values in an if statement?
ITERATIVE DEVELOPMENT:
Documenting the use of:
selecting & displaying the correct chocolate bar without using an array (see task 09 / task 09 ext)
selecting & displaying the correct chocolate bar using an array
Then explaining why you used one over the other is a good example of Iterative Development.