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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OR/AND statement in Javascript (i'm a beginner)

    if i type "sure" in the prompt
    it does work but if it type "yes" it doesn't alert


    code:
    <script type="text/javascript">
    var comment = prompt("nice site?")
    var positive = "yes" || "sure"
    if (comment = positive)
    {
    alert ("thanks")
    }

    i also tried putting && between it but....
    help!

  • #2
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i mean
    <script type="text/javascript">
    var comment = prompt("nice site?")
    var positive = "yes" || "sure"
    if (comment == positive)
    {
    alert("thanks")
    }

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    <script type="text/javascript">
    var comment = prompt("nice site?");
    
    if (comment == "yes" || comment == "sure") {
        alert("thanks");
    }
    </script>
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 343 Times in 339 Posts
    Quote Originally Posted by knownasniels View Post
    if i type "sure" in the prompt
    var positive = "yes" || "sure"
    note: positive will always be "yes" since a non-empty string is a truthy value (and that doesn’t trigger the alternate value).

    other than that, what Andrew said.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx for reactions
    i thought it would be handy to list them up
    but it doesn't work...
    thx for other suggestions


  •  

    Posting Permissions

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