Answer to Question #3234 in AJAX | JavaScript | HTML | PHP for lee

Question #3234
line 9 /*
line 10 * Program designed to find how many of a series of video tracks
line 11 * will fit on a DVD the user is prompted to input the track lengths
line 12 * one by one. When the total exceeds the capacity of the disk
line13 * user is informed how many tracks this took
line 14 */
line 15 var input;
line 16 var total;
line 17 var capacity;
line 18 var count;
line 19 total = 0;
line 20 capacity = 120
line 21 count = 0;
line 22
line 23 input = window.prompt
line 24 (‘please enter a track length in minutes’,’’);
line 25 input = parsefloat(input);
line 26 total = total + input;
line 27 while (total<=capacity)
line 28 {
line 29 document.write(‘track length ‘ + input + ‘<BR>’)
line 30 count = count + 1;
line 31 input = window.prompt
line 32 (‘please enter a track length in minutes’,’’);
line 33 input = parsefloat(input);
line 34 total = total + input;
line 35 }
line 36 document.writ
line 37 (‘ the capacity was exceeded after ‘ + count + ‘ track(s) . ‘);


(a) Lines 9 to 14 in Figure 1 are an example of an extended comment. What is the purpose of comments and how are they treated by the JavaScript interpreter?
(b) What do lines 25 and 33 do and what difference would it make if they were left out?
(c) Describe in detail what happens when the statement
document.write('Track length ' + input + '<BR>');
at line 29 is executed.

(d) Suppose the programmer accidentally missed out line 30. Explain what would be output in that case when the statement on lines 36 and 37 was executed.
(e) If the programmer also missed out line 21 (so that both lines 21 and 30 are missing) what would then be output when the statement on lines 36 and 37 was executed? Explain your answer.
(f) Suppose the braces {and } at lines 28 and 35 were left out. Explain what would happen if the program was executed and the user entered 10 when prompted.
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS