Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1; using alert() and console.log(): Create an HTML document that uses the J

ID: 3542940 • Letter: P

Question

Part 1; using alert() and console.log(): Create an HTML document that uses the JavaScript alert() method to display "Hello from <your name>" in a pop-up box on the screen. This isn't hard. Just wrap the document.write() statement similar to the one in the lecture slides in appropriate <script> tags in a simple HTML document. Name your document l4p1a.html and make a link to it from your home page.

To your l4p1 page, right after the alert() call, use the console.log() method to log the message "Alert displayed" to the logging facility. Use the console log facility of Firefox with Firebug or Chrome to verify that the message was logged.


Part 2; JavaScript loops and document.write(): The first four terms of the Perrin sequence are 3, 0, 2, 3. Thereafter, each number is the sum of the second and third preceding terms, so the next is 0 + 2 = 2 and the one after that is 2 + 3 = 5, and so on. Compute the first 20 terms of the Perrin sequence using JavaScript. Use document.write()and place the numbers in a table one column wide by 20 rows long in a Web document. Name your document l4p2.html and create a link to it from your home page. Note that you must compute the numbers JavaScript; hard-coding them will not do! (Hint: the FOR loop is your friend. You do not necessarily need an array to solve this, but you do need to keep track of the last three terms. An array of three elements may be the easiest approach. Write some pseudocode before you start coding JavaScript,) 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 40 terms of the Perrin sequence? Why did you have to usedocument.write() instead of alert() for this exercise?

Include the answers in the same document as the table of numbers.

Explanation / Answer

################## l4p1a.html #############


<!--

To change this template, choose Tools | Templates

and open the template in the editor.

-->

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

window.onload =function myfunction()

{

var aler=alert("Hello from sheetal");

console.log(aler,"logged");

};

</script>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<div></div>

</body>

</html>