{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

JavaScriptExample - I s This example contains logical...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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("Incorrect Number!! Please reload page!!") } // Discount Calculations total = googleshares + hpshares+ dellshares if (total > 15) { alert("You receive 20% discount!!!!") // set discount to 20%, which is the same as 0.20 } else if ((googleshares >= 5) && (hpshares >= 3)) { alert("You receive 15% discount!!!") // set discount } else if ((googleshares >= 3) || (dellshares >= 7)) Sheet1 Page 2 { alert("You receive 10% discount!!") // set discount } else if (hpshares >= 5) { alert("You receive 5% discount!") // set discount } else document.write("Sorry! ZERO discount for you!<br>") // insert code to compute and display the total cost </script> </body> </html>...
View Full Document

{[ snackBarMessage ]}