Imagine you are writing a computer program that creates a customised children's story using names provided by the user of the program. Your first attempt at the program prompts the user for the gender and name of the hero, the type and name of their pet, and writes the first two sentences of the story.
For instance, if the user provides the following information: 'F' (for female), Poppy, cat, Jess, the program will produce the output given in Figure 4:
Note: Figure in the attached Question.pdf document
A skeleton version of the program which is to produce the output as shown in Figure 4 can be found in the file M150_TMA02_2011B_Q4(iii).html that you downloaded with this assignment. Open this file and save it as M150_TMA02_2011B_Q4(iii)_answer.html.
Look at the skeleton program and answer part (a) below. Then develop the program by editing your answer file step-by-step as specified in parts (b) to (e). (You may find it useful to look at Activity 2.10 in Unit 7 and its solution.) The first two lines of code have been written for you. The user is prompted for the hero's gender ('F' or 'M') and the hero's name. (Note the need for the escape character before the apostrophe in the prompt string.)
(a) What is the purpose of the second argument 'F' in the statement
heroGender = window.prompt('Is the hero female or male? Enter F or M', 'F'); ?
(b) Write the next two lines of code (as indicated by the comments in the code file) to prompt the user for the type of pet (i.e. what type of animal it is) and the name of the pet.
The program is not expected to check that what the user enters makes sense. It should simply accept whatever is input.
Run the program and check that it prompts for four inputs in total. (You can enter whatever you like in response to each prompt. The program will not yet produce any output.)
Take a screenshot of the prompt for the name of the pet and insert the screenshot into your Solution Document along with the two lines of code you have added.
(c) Write a line of code to output 'Once upon a time there was a ' (note the space at the end). Run the program and check that it now prompts for four inputs then writes this output. Insert this line of code in your Solution Document.
(d) You now need a selection structure to decide whether to output 'girl ' or 'boy '. Here is the required algorithm:
if heroGender is 'F'
output 'girl '
output 'boy '
Using this algorithm, write the code and test that it works. Insert the selection code in your Solution Document.
(e) Write the code to produce the remaining output, as in Figure 4. The second sentence should appear on a new line. Take a screenshot of the output from your final program. It should be similar to Figure 4, but with different details. Insert the screenshot and the code you have written for this part into your Solution Document.© BrainMass Inc. brainmass.com July 17, 2018, 9:28 am ad1c9bdddf
The second argument 'F' is the default input. Once the above line executes, it will
prompt the user with the following message "is the hero female or male? "And as a
default value, the input field will contain the 'F'.
// prompt the ...