Question
Using Notepad ++ or Nano Part 1; JavaScript loops and document.write(): An arithmetic sequence is an ordered list of numbers with a defined starting point
Using Notepad ++ or Nano
Part 1; JavaScript loops and document.write(): An arithmetic sequence is an ordered list of numbers with a defined starting point and a constant difference, d, from one term to the next. For example, the sequence starting at zero with d=3 is 0, 3, 6, 9, 12, ...
Write JavaScript to compute the first 20 terms of a sequence beginning at 7 with d=9. (To check your work, the first few terms are 7, 16, 25, 34.) Use document.write() to place the result in a one-column table on your web page. Name your document l4p1.html and create a link to it from your home page. Note that you must compute the numbers using JavaScript; hard-coding them will not do! (Hint: the FOR loop is your friend.) Your JavaScript code must also generate the necessary table row and table data tags. Check your output carefully; errors will count against you.
Answer the following questions: What would you have to change to make your program produce the first 30 terms of the series? Why did you have to use document.write() instead of alert() for this exercise?
Include the answers in the same document as the table of numbers.
Note: There are better ways than document.write() to include dynamic information in web pages, but we haven't gotten to them yet.
Part 2; suppressing default actions: Build a new Web page named l4p2.html with a link back to your index page. The text of the link must be "Do not click here." Test that clicking the link really takes you to your index page. Now use JavaScript to create an alert with the message "Stop that!" that is displayed when the link is clicked. Clicking the link should not any longer take you anywhere. (However, the browser's "Back" button will continue to work so there's some way out of there!) Make a link from your index page to l4p2html.
Do not change the href= portion of the link. Do it all with JavaScript. The whole point of this exercise is for you to learn how use JavaScript to prevent the default action of an HTML element like a link, OK?
Part 3; using form values for computation with JavaScript: Copy the order form from Lab Exercise 2, Part 3 to l4p3.html. (You can use the Unix command cp l2p3.html l4p3.html to do this or copy it locally and upload the copy with your SFTP tool.) Make a link to this new file from your index page.
Add JavaScript to your program to compute the total cost of the order. The total cost will be the sum of the price of each item times the quantity ordered times 1.07 to allow for taxes. Use a JavaScript confirm() call to display "The total cost of your order is (whatever the cost is)." The confirm() function displays a message box with your message and buttons for "OK" and "Cancel." It returns true of the "OK" button is clicked and false if the cancel button is clicked.
If the user of your form clicks OK, the form should be submitted to formtest.php as before. However, if the user clicks "Cancel" the form should not be submitted. See Part 2 for a strong hint on how to do this.
Your computed answer may not look like a dollar amount because JavaScript numbers are floating point. That is OK; you need not correct it. If the messy output bothers you, check JavaScript's toFixed function. It is still possible for your answer to be incorrect in the last penny because toFixed() truncates rather than rounding. That is OK too, but if you want to be exactly correct, add just under 1/2 cent (0.0049) to your computed value before calling toFixed().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started