Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript">
- /*
- A global variable named customertype should be created outside of the functions.
- This variable will be initialized with a value (i.e. customertype = "direct" ) and will be
- used by the functions below.
- ** Not included in your original script **
- */
- var customertype = 'direct'; // Because customertype was defined on the root level, with var, it is now global.
- /* Not sure why you had the ELSE statments... */
- function displaytype() {
- if (customertype == "direct") {
- alert("Buy Now! From this web page! My children need new shoes!");
- }
- if (customertype == "advertising") {
- alert("Support our advertisers! Click on an ad, so I can make money!");
- }
- if (customertype == "subscription") {
- alert("Renew your subscription today! My children need medicine!");
- }
- }
- /*
- A function named "changetype()". The function will change the customer type each time
- it is run. It should change "direct" to "advertising", "advertising" to "subscription" and
- "subscription" to "direct". It does NOT do all three at the same time, it would take
- three calls to the function to change the value of customertype three times.
- ** You successfully determine what the newtype should be, but you do not set customertype to the newtype. **
- */
- function changetype() {
- var newtype = "direct";
- if (customertype == "direct") {
- newtype = "advertising" ;
- alert("Customer has been changed to Advertising");
- }
- if (customertype == "advertising") {
- newtype = "subscription";
- alert("Customer has been changed to Subscription");
- }
- if (customertype == "subscription") {
- newtype = "direct"; // Reduntant as the default value of newtype is already 'direct'
- alert("Customer has been changed to Direct");
- }
- customertype = newtype;
- }
- /* You were also missing your closing script tag */
- </script>
- </head>
- <body>
- <a href="Javascript: displaytype();">Todays Special</a><br>
- <a href="Javascript: changetype();">Change Customer Type</a><br>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement