Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

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


(!)

turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 476 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
18-Jun-2012, 09:09 PM #1
Solved: Learning JavaScript coding, whats wrong with this code?
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 Thumbnails
Solved: Learning JavaScript coding, whats wrong with this code?-javascript-coding.png  
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
18-Jun-2012, 09:39 PM #2
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.
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 476 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
19-Jun-2012, 02:54 AM #3
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.
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 08:21 AM #4
So this didn't work?

Code:
else
{
console.log("did you pass");
}
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 08:23 AM #5
Might also be the codeacademy editor...as in, you may need a semicolon after else...

Code:
else;
{
console.log("stuff");
}
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 476 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
19-Jun-2012, 01:55 PM #6
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 Thumbnails
Solved: Learning JavaScript coding, whats wrong with this code?-javascript-coding-2.png  
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 02:25 PM #7
Do they have the function already added for you in code academy?

This works in the real world called by a button:

Quote:
function testfunction()
{
if (4>6)
{
alert("Let's go");
}
else
{
alert("no");
}
}
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,270 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
19-Jun-2012, 02:27 PM #8
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?"
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 02:28 PM #9
Quote:
Originally Posted by Ent View Post
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?"
Ent, that's why I asked about codeacademy. Their setup is different there if I remember correctly. As in, different than a normal editor.
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,270 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
19-Jun-2012, 02:31 PM #10
Quote:
Originally Posted by ckphilli View Post
Ent, that's why I asked about codeacademy. Their setup is different there if I remember correctly. As in, different than a normal editor.
Why ever would they do that? Very strange.
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 02:31 PM #11
Quote:
Originally Posted by Ent View Post
Why ever would they do that? Very strange.
It is...but again, that's if I remember correctly. It's been a while.
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 02:37 PM #12
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
}
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 476 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
19-Jun-2012, 03:15 PM #13
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 Thumbnails
Solved: Learning JavaScript coding, whats wrong with this code?-javascript-coding-3.png  
ckphilli's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,292 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
19-Jun-2012, 03:21 PM #14
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.
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 476 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
19-Jun-2012, 03:35 PM #15
What do you mean by delete the comment between. Only part you lost me on. You mean delete "fill in here:" part?
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


Tags
javascript coding

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑