Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Online

    21
    ReputationRep:
    how do i do if value 1,2 and 3 all equal to specific answer and then that if statement should work...



    function checkanagram(){
    var val = $("#anagramtext".val();
    var val2 = $("#anagramtext2".val();
    var val3 = $("#anagramtext3".val();

    if (val == 'Millennium Wheel' {

    alert ('Correct Answer!'; }

    else { alert ('Incorrect answer, try again'; }

    }




    i want it to say if value1 ,2 and 3 all equal to each specific string then it should do the if statement
    • Thread Starter
    Online

    21
    ReputationRep:
    any ideas UWS
    • Thread Starter
    Online

    21
    ReputationRep:
    Any ideas IWMTom Dragon5555
    • Community Assistant
    Offline

    18
    ReputationRep:
    Just put all conditions into your if statement one after the other?
    • Very Important Poster
    • Welcome Squad
    Offline

    20
    ReputationRep:
    Use the && operator to represent AND

    Code:
    if (val == 'Millennium Wheel' && val2 == 'Millennium Wheel' && val3 == 'Millennium Wheel')
    
    {...}
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by UWS)
    Use the && operator to represent AND

    Code:
    if (val == 'Millennium Wheel' && val2 == 'Millennium Wheel' && val3 == 'Millennium Wheel';)
    
    {...}
    i did that it didnt work
    • Community Assistant
    Offline

    18
    ReputationRep:
    (Original post by study beats)
    i did that it didnt work
    You've done something else wrong then. Paste your code into a JSFiddle.
    • Very Important Poster
    • Welcome Squad
    Offline

    20
    ReputationRep:
    (Original post by study beats)
    i did that it didnt work
    Not sure then, some of that is jQuery which I've never used.

    Have you considered asking on StackOverflow too?
    https://stackoverflow.com/
    Offline

    18
    ReputationRep:
    Dont you wanna use "or" to check if one of those is the correct or do they all have to be correct...



    if (val == 'Millennium Wheel' || val2 == 'Millennium Wheel' || val3 == 'Millennium Wheel'
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by John10101)
    Dont you wanna use "or" to check if one of those is the correct or do they all have to be correct...



    if (val == 'Millennium Wheel' || val2 == 'Millennium Wheel' || val3 == 'Millennium Wheel'
    all have to be correct
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by IWMTom)
    You've done something else wrong then. Paste your code into a JSFiddle.
    how do i post into js fiddle ? can anyone do it?
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by UWS)
    Not sure then, some of that is jQuery which I've never used.

    Have you considered asking on StackOverflow too?
    https://stackoverflow.com/
    i have tried it again. now only val 3 isnt working
    • Community Assistant
    Offline

    18
    ReputationRep:
    (Original post by study beats)
    how do i post into js fiddle ? can anyone do it?
    Yes... Go to the website, pop you JavaScript into the JS box, and your HTML in the HTML box.

    Make the smallest possible working example for your scenario.
    Offline

    18
    ReputationRep:
    (Original post by study beats)
    how do i post into js fiddle ? can anyone do it?
    https://jsfiddle.net/ go there put all your code there and save it and send link.
    • Very Important Poster
    • Welcome Squad
    Offline

    20
    ReputationRep:
    (Original post by study beats)
    i have tried it again. now only val 3 isnt working
    It should work if the first two work, maybe you're missing an apostrophe or the &&?

    (Original post by study beats)
    how do i post into js fiddle ? can anyone do it?
    https://jsfiddle.net/
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by IWMTom)
    Yes... Go to the website, pop you JavaScript into the JS box, and your HTML in the HTML box.

    Make the smallest possible working example for your scenario.
    https://jsfiddle.net/a8xykcj9/4/

    (Original post by John10101)
    https://jsfiddle.net/ go there put all your code there and save it and send link.
    https://jsfiddle.net/a8xykcj9/4/

    (Original post by UWS)
    It should work if the first two work, maybe you're missing an apostrophe or the &&?



    https://jsfiddle.net/
    https://jsfiddle.net/a8xykcj9/4/
    • Community Assistant
    Offline

    18
    ReputationRep:
    (Original post by study beats)
    *****
    Here's a working POC: https://jsfiddle.net/wuxtubnw/
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by IWMTom)
    Here's a working POC: https://jsfiddle.net/wuxtubnw/
    still not working, is it because i am using spaces?
    • Community Assistant
    Offline

    18
    ReputationRep:
    (Original post by study beats)
    still not working, is it because i am using spaces?
    What's showing in your error log?
    • Thread Starter
    Online

    21
    ReputationRep:
    (Original post by IWMTom)
    What's showing in your error log?
    basically for value 3, when i choose it to equal to 'Tower of London' then it doesnt work and when i type it into the field box the dialog box shows up as incorrect answer even though i have spelt it properly.

    also i have tried other words and they work
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Break up or unrequited love?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.