1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Learning JavaScript coding, whats wrong with this code?

Discussion in 'Software Development' started by turbow5, Jun 18, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    If this isn't the right section forum please let me know but I stumbled across this website and I cant tell what I'm doing wrong with the coding. In attachment.
     

    Attached Files:

  2. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    For an if statement, you're basically saying...if x happens, do y, else do z. Here's our wiki entry on it: http://library.techguy.org/wiki/IF_Statement

    For your code, you coded if x happens, do y else z do. See the difference?

    Your console.log should be between the curly braces.
     
  3. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    I'm still not getting this, I put them between curly braces and it didn't pass me. Could you right out what its suppose to be on line 5?

    That way i can compare them.
     
  4. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    So this didn't work?

    Code:
    else
    {
    console.log("did you pass");
    }
    
     
  5. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    Might also be the codeacademy editor...as in, you may need a semicolon after else...

    Code:
    else;
    {
    console.log("stuff");
    }
     
  6. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    It still says line 5 i s wrong, I line 6 to like 5 with and without curly braces and the ";" symbol and It says there's something wrong with the "else" and I used ";" on that also.
     

    Attached Files:

  7. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    Do they have the function already added for you in code academy?

    This works in the real world called by a button:

     
  8. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,410
    No no no no no.
    You don't put the semicolons in after the If or Else statements.
    Remember that the semicolon is to Javascript what the full stop is to us.
    I wouldn't say

    If. you're feeling hungry have a sandwich.

    I'd say

    If you're feeling hungry have a sandwich.


    The "missing operator" error is because it sees "If. " and wonders "If what?"
     
  9. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    Ent, that's why I asked about codeacademy. Their setup is different there if I remember correctly. As in, different than a normal editor.
     
  10. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,410
    Why ever would they do that? Very strange.
     
  11. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    It is...but again, that's if I remember correctly. It's been a while.
     
  12. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    I was in fact mistaken...or they changed it. Anyway, turbow5, take out the semicolons after the if and the else...so something like this:

    Code:
    if(4>6)
    {
    //do stuff
    }
    else
    {
    //do other stuff
    }
    
     
  13. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    Wait I thought anything begging with a // was a note to yourself that the computer ignores? Yet it worked but now there's a error on line 9 and I don't know what I even did. (checked the Q&A and there's answers for every question except this one.) Also you said codecademy was different. What would you suggest then?

    Remember to answer whats wrong with line 9 though.
     

    Attached Files:

  14. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,386
    No, forget the codeacademy specific stuff.

    The slashes are for comments. Remove them from your code and delete the last 2 curly braces and the comment between.

    Also, your forgot the semicolons after your alert statement and console.log statement.
     
  15. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    What do you mean by delete the comment between. Only part you lost me on. You mean delete "fill in here:" part?
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1057635