www.webdeveloper.com
Results 1 to 5 of 5

Thread: I'd appreciate any help

  1. #1
    Join Date
    Jan 2011
    Location
    New York
    Posts
    1

    I'd appreciate any help

    I'm new to JavaScript. It's still very much a learning process here. I'm trying to learn from a book, and it's had varying degrees of success. I'm going to post a script, and I'd appreciate it if you could point out the errors. There's definitely something wrong with it, as it's not working.

    var promotionCode;


    promotionCode = window.prompt('What is your promotion code?','');

    If (promotionCode = 'FSSAVE')
    {
    document.write('You get two free 10 by 8 prints!');
    }
    Else
    {
    If (promotionCode = 'ISSAVE')
    {
    document.write('You get one free 12 by 10 print!');
    }
    Else
    {
    If (promotionCode = 'SOSAVE')
    {
    document.write('You get a free display album!');
    }
    Else
    {
    document.write('Invalid promotional code');
    }
    }
    }

    Again, thanks for any help you could give me

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Quote Originally Posted by Marty3 View Post
    I'm new to JavaScript. It's still very much a learning process here. I'm trying to learn from a book, and it's had varying degrees of success.
    Does it talk about JavaScript being case-sensitive?

    Does it talk about the importance of distinguishing between the assigment = and equality == operators ?

    Does it talk about the importance of always using the error console? Firefox / Tools / Error Console

  3. #3
    Join Date
    Mar 2010
    Posts
    2,803
    1 obvious error is the misuse of =.

    "=" is for assigning values eg: var str = 'hello world';

    "==" is for comparing values eg if(a == 2)

  4. #4
    Join Date
    Aug 2009
    Posts
    593
    Wow, there seemed to be so many brackets in there??

    Code:
    var promotionCode = prompt('What is your promotion code?', '');
    
    if (promotionCode === 'FSSAVE') {
    	document.write('You get two free 10 by 8 prints!');
    } else
    if (promotionCode === 'ISSAVE') {
    	document.write('You get one free 12 by 10 print!');
    } else
    if (promotionCode === 'SOSAVE') {
    	document.write('You get a free display album!');
    } else {
    	document.write('Invalid promotional code');
    }
    Like tirna said, JavaScript is case-sensitive, so words like if and else should always be lowercase.

  5. #5
    Join Date
    Mar 2010
    Posts
    2,803
    Have a look at comparison operators

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles