Solutions Manual Internet and World Wide Web How to Program 5th Edition Deitel

September 28, 2017 | Author: answer | Category: Control Flow, Areas Of Computer Science, Software Engineering, Computer Programming, Computing
Share Embed Donate


Short Description

Dowload link: https://goo.gl/2ysn8x internet and world wide web how to program solution manual pdf internet and world ...

Description

Solutions Manual Internet and World Wide Web How To Program 5th Edition Deitel Download full at:

https://testbankdata.com/download/solutions-manualinternet-world-wide-web-program-5th-edition-deit el/

8

JavaScript: Control Statements II, Solutions

Who can control his fate? —William Shakespeare

Not everything that can be counted counts, and not every thing that counts can be counted. —Albert Einstein

Objectives In this chapter you’ll: ■

Learn the essentials of counter-controlled repetition



Use the for and do…while repetition statements to execute statements in a program repeatedly.



Perform multiple selection using the switch selection statement.



Use the break and continue program-control statements



Use the logical operators to make decisions.

Self-Review Exercises 8.1 State whether each of the following is true or false. If false, explain why. a) The default case is required in the switch selection statement.

252

Chapter 8 JavaScript: Control Statements II, Solutions ANS: False. The default case is optional. If no default action is needed, then there’s no

need for a default case. b) The break statement is required in the last case of a switch selection statement. ANS: False. The break statement is used to exit the switch selection statement. The break statement is not required for the last case in a switch selection statement. c) The expression ( x > y && a < b ) is true if either x > y is true or a < b is true. ANS: False. Both of the relational expressions must be true for the entire expression to be true when using the && operator. d) An expression containing the || operator is true if either or both of its operands is true. ANS: True. 8.2

Write a JavaScript statement or a set of statements to accomplish each of the following tasks: a) Sum the odd integers between 1 and 99. Use a for structure. Assume that the variables sum and count have been declared. ANS: sum = 0;

for

( count = 1; count Solution 8.6 var var var var var

i; input; amount; current; smallest;

input = parseInt( window.prompt( "How many numbers?", "0" ) ); amount = parseInt( input ); if ( input !== 0 ) { input = window.prompt( "Enter first integer:", "0" ); smallest = parseInt( input ); document.writeln( "Number entered: " + smallest ); } // end if for ( i = 2 ; i Solution 8.8 table { width: 300px; border-collapse: collapse; background-color: lightblue; margin: 10px;} table, td, th { border: 1px solid black; padding: 4px; } th { text-align: left; color: white; background-color: darkblue; } tr.oddrow { background-color: white; } var principal = 1000.0;

258

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

Chapter 8 JavaScript: Control Statements II, Solutions

for ( var interestRate = 5; interestRate Solution 8.10 p { margin-top: 0; margin-bottom: 0; } p.firstline { margin-top: 20px; } document.writeln( "The Twelve Days of Christmas" ); for ( var day = 1; day 105 106 107

263

"Five golden rings." );

"Four calling birds," );

"Three French hens," );

"Two turtle doves, and" );

"a Partridge in a pear tree.");

264

Chapter 8 JavaScript: Control Statements II, Solutions

8.11 A mail-order house sells five different products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write a script that reads a series of pairs of numbers as follows: a) Product number b) Quantity sold for one day Your program should use a switch statement to help determine the retail price for each product and should calculate and output HTML5 that displays the total retail value of all the products sold last week. Use a prompt dialog to obtain the product number and quantity from the user. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results. ANS:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

table { width: 100% } th { text-align: left } Solution 8.11 var product1 = 0; var product2 = 0; var product3 = 0;

Exercises

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

var var var var

265

product4 = 0; product5 = 0; inputString; productId = 1;

while ( productId != 0 ) { inputString = window.prompt( "Enter product number ( 1-5 ) ( 0 to stop ):" ); productId = parseInt( inputString ); if ( productId >= 1 && productId = 1 && j < 4 );

ANS: true

d)

document.writeln( m = i || k == m );

ANS: true

f)

document.writeln( k + m < j || 3 - j >= k );

ANS: false [Note: The | in part (f) should be ||.]

g)

267

document.writeln( !( k > m ) );

ANS: false [Note: These parentheses are necessary.]

268 8.13 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Chapter 8 JavaScript: Control Statements II, Solutions Given the following switch statement:

switch ( k ) { case 1: break; case 2: case 3: ++k; break; case 4: --k; break; default: k *= 3; } x = k;

What values are assigned to x when k has values of 1, 2, 3, 4 and 10? ANS: x = 1, x = 3, x = 4, x = 3 and x = 30, respectively.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF