JavaScriptExample

JavaScriptExample - I s // This example contains logical...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 <html> <head> <title>Javascript Example 2</title> </head> <body> <h1>Welcome to the FAKE Stock Exchange Market</h1> <hr><br><br> <!-- This is an HTML COMMENT --> <!-- Now start your script --> <script type="text/javascript"> // Javascript comment - All variables should be declared at the beginning // This programming style produces more readable code var googleshares var googleprice = 600 var hpshares var hpprice = 80 var dellshares var dellprice = 30 var a var total = 0 var cost = 0 var discount = 0 //welcome message alert("Welcome to our fake stock market!") // a few inputs googleshares = 1 * prompt("How many Google shares do you want?") hpshares = 1 * prompt("How many HP shares do you want?") dellshares = 1 * prompt("How many DELL shares do you want?") // confirm function: if user clicks ok, confrm returns true, otherwise it returns false a = confirm("You want " + googleshares + " Google shares, " + hpshares + " HP shares and " + dellshares + " DELL shares.\n
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: I s // This example contains logical ERRORS. Make sure you fix them if (a=false) { alert(&quot;Incorrect Number!! Please reload page!!&quot;) } // Discount Calculations total = googleshares + hpshares+ dellshares if (total &gt; 15) { alert(&quot;You receive 20% discount!!!!&quot;) // set discount to 20%, which is the same as 0.20 } else if ((googleshares &gt;= 5) &amp;&amp; (hpshares &gt;= 3)) { alert(&quot;You receive 15% discount!!!&quot;) // set discount } else if ((googleshares &gt;= 3) || (dellshares &gt;= 7)) Sheet1 Page 2 { alert(&quot;You receive 10% discount!!&quot;) // set discount } else if (hpshares &gt;= 5) { alert(&quot;You receive 5% discount!&quot;) // set discount } else document.write(&quot;Sorry! ZERO discount for you!&lt;br&gt;&quot;) // insert code to compute and display the total cost &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;...
View Full Document

This note was uploaded on 04/02/2008 for the course COMP APPS 170 taught by Professor Gayatreeganu during the Spring '08 term at Rutgers.

Page1 / 2

JavaScriptExample - I s // This example contains logical...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online