Advertisement
gitlez

YA: Javascript Customer Message Display

Sep 7th, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.76 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.             /*
  5.                 A global variable named customertype should be created outside of the functions.
  6.                 This variable will be initialized with a value (i.e. customertype = "direct" ) and will be
  7.                 used by the functions below.
  8.                
  9.                 ** Not included in your original script **
  10.             */
  11.             var customertype = 'direct'; // Because customertype was defined on the root level, with var, it is now global.
  12.            
  13.            
  14.            
  15.             /* Not sure why you had the ELSE statments... */
  16.             function displaytype() {
  17.                 if (customertype == "direct") {
  18.                     alert("Buy Now! From this web page! My children need new shoes!");
  19.                 }
  20.                 if (customertype == "advertising") {
  21.                     alert("Support our advertisers! Click on an ad, so I can make money!");
  22.                 }
  23.                 if (customertype == "subscription") {
  24.                     alert("Renew your subscription today! My children need medicine!");
  25.                 }
  26.             }
  27.  
  28.            
  29.            
  30.             /*
  31.             A function named "changetype()". The function will change the customer type each time
  32.             it is run. It should change "direct" to "advertising", "advertising" to "subscription" and
  33.             "subscription" to "direct". It does NOT do all three at the same time, it would take
  34.             three calls to the function to change the value of customertype three times.
  35.            
  36.             ** You successfully determine what the newtype should be, but you do not set customertype to the newtype. **
  37.             */
  38.             function changetype() {
  39.                 var newtype = "direct";
  40.  
  41.                 if (customertype == "direct") {
  42.                     newtype = "advertising" ;
  43.                     alert("Customer has been changed to Advertising");
  44.                 }
  45.                 if (customertype == "advertising") {
  46.                     newtype = "subscription";
  47.                     alert("Customer has been changed to Subscription");
  48.                 }
  49.                 if (customertype == "subscription") {
  50.                     newtype = "direct"; // Reduntant as the default value of newtype is already 'direct'
  51.                     alert("Customer has been changed to Direct");
  52.                 }
  53.                 customertype = newtype;
  54.             }
  55.            
  56.             /* You were also missing your closing script tag */
  57.         </script>
  58.     </head>
  59. <body>
  60.     <a href="Javascript: displaytype();">Todays Special</a><br>
  61.     <a href="Javascript: changetype();">Change Customer Type</a><br>
  62.    
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement