Question: Step 2 : Examine the code that produced this card, and find the Javascript script that produced the output for this portion of the card.
Step 2: Examine the code that produced this card, and find the Javascript script that produced the output for this portion of the card. On your lab sheet, show the code the contains the values for the prices array. What is the value of prices[0] ? What is the value of prices[1] ?
Step 3: What needs to be changed? Revise the code so that it prints a different number of houses each time through the loop, rather than simply "With 1 House" repeatedly.
Step 4: Did that work? It is likely that the number of houses you print does not exactly look right. For instance, you may see "With 0 Houses" or "With 01 Houses" where you wanted "With 1 House". If that is the case, here are some hints you may find useful:
the values of i are 0, 1, 2, and 3, but the elements of the array are prices[0], prices[1], prices[2], and prices[3]. Unfortunately, you don't want to print "With i Houses", but rather "With i+1 Houses".
when JavaScript is asked to mix strings and numbers together in its output, it can usually do a good job of treating each of them appropriately. But it can get confused when you then try to add two numbers, (like "i+1") and treat them both as strings.
in order to get "i+1" to be processed as an actual arithmetic statement, rather than a string concatenation, remember that things inside parentheses are processed first. Thus, using "(i+1)" should work better. You can also tell JavaScript to treat the expression as an integer, by using the function call "parseInt(i+1)" there.
Converting your own Monopoly card to make use of arrays is part of the final homework assignment.
The code is:
| TITLE DEED WHITECHAPEL ROAD | |
|---|---|
| RENT £4. | |
| With HOTEL £450. | |
| Mortgage Value £30. | |
| Houses Cost £50. each | |
| Hotels, £50. plus 4 houses | |
| Adaptation of the Original Monopoly game. © 1935 Hasbro, Inc. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
