using an ordinary ASCII text editor such as pico or vi. You may not use HTML or
ID: 3854561 • Letter: U
Question
using an ordinary ASCII text editor such as pico or vi. You may not use HTML or wysiwyg editors. use notepad++
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.
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.
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
Explanation / Answer
The following javascript function is used to create a table dynamically.
for 1st part: you can use the following code in javascript
function gp(var start, var diff, var noofTerms){
var arr= [];
for(i=start; i<=noofTerms;i+diff){
arr.push(i);
}
for(i=0; i<=arr.length;i++){
document.writeln(arr[i]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.