23.07.2013 Views

JavaScript/JScript: Control Structures I - Pearson Learning Solutions

JavaScript/JScript: Control Structures I - Pearson Learning Solutions

JavaScript/JScript: Control Structures I - Pearson Learning Solutions

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2008934301<br />

Chapter 14 <strong>JavaScript</strong>/<strong>JScript</strong>: <strong>Control</strong> <strong>Structures</strong> I 443<br />

14.23 Write a script that reads in the size of the side of a square and outputs HTML text that displays<br />

a hollow square of that size out of asterisks. Use a prompt dialog to read the size from the user.<br />

Your program should work for squares of all side sizes between 1 and 20.<br />

14.24 A palindrome is a number or a text phrase that reads the same backward as forward. For example,<br />

each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611.<br />

Write a script that reads in a five-digit integer and determines whether it is a palindrome. If the number<br />

is not five digits, output HTML text that displays an alert dialog indicating the problem to the<br />

user. When the user dismisses the alert dialog, allow the user to enter a new value.<br />

14.25 Write a script that outputs HTML text that displays the following checkerboard pattern:<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

* * * * * * * *<br />

Your program may use only three output statements, one of the form<br />

one of the form<br />

document.write( "* " );<br />

document.write( " " );<br />

and one of the form<br />

document.writeln( "" );<br />

[Hint: Repetition structures are required in this exercise.]<br />

14.26 Write a script that outputs HTML text that keeps displaying in the browser window the multiples<br />

of the integer 2, namely 2, 4, 8, 16, 32, 64, etc. Your loop should not terminate (you should<br />

create an infinite loop). What happens when you run this program?<br />

14.27 A company wants to transmit data over the telephone, but they are concerned that their<br />

phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to<br />

write a program that will encrypt their data so that it may be transmitted more securely. Your script<br />

should read a four-digit integer entered by the user in a prompt dialog and encrypt it as follows: Replace<br />

each digit by (the sum of that digit plus 7) modulus 10. Then swap the first digit with the third,<br />

and swap the second digit with the fourth. Then output HTML text that displays the encrypted integer.<br />

Write a separate program that inputs an encrypted four-digit integer and decrypts it to form the original<br />

number.<br />

e-Business and e-Commerce: How to Program, by Harvey M. Deitel, Paul J. Deitel, and Tem R. Nieto. Published by Prentice Hall.<br />

Copyright © 2001 by <strong>Pearson</strong> Education, Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!