Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Help =/

  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help =/

    Hi i've been trying well over an hour to get this small code to work, but it just won't....please help!
    I just want it to be able to reply to 3 responses and an answer to any other thing that is said, thanks.

    var value = prompt("Hi! How are you?", "Answer good, bad or ok.");
    var answer = (value);
    var greeting = function(answer) {
    if (answer === good)
    {
    console.log("That's great! Have a nice day!");
    }
    else if (answer === bad)
    {
    console.log("Aw =/ I hope things get better for you soon!");
    }
    else if (answer === ok)
    {
    console.log("That's good! Have a nice day!");
    }
    else
    {
    console.log("Sorry, I don't understand.");
    }
    };
    greeting();

  • #2
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    PHP Code:
    var greeting = function(answer) {
        if (
    answer === 'good')
        {
            
    console.log("That's great! Have a nice day!");
        }
        else if (
    answer === 'bad')
        {
            
    console.log("Aw =/ I hope things get better for you soon!");
        }
        else if (
    answer === 'ok')
        {
            
    console.log("That's good! Have a nice day!");
        }
        else 
        {
            
    console.log("Sorry, I don't understand.");
        }
    }; 
    The answers are strings, strings must be either single quoted or double quoted.

  • #3
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Actually, aside the string error, you forgot to give the function a parameter.
    here is a working version.


    http://jsfiddle.net/Me5xf/

    NOTE: Open up the console.

  • Users who have thanked 0x3 for this post:

    smiggle04 (09-10-2013)

  • #4
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thankyou


  •  

    Posting Permissions

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