Jump to content

Suck on Codecademy

Go to solution Solved by CornOnJacob,

Here is my code if you want to see something that should theoretically work:

//Write your function below. //Don't forget to call your function!var sleepCheck = function(numHours) {    if (numHours >= 8){	return("You're getting plenty of sleep! Maybe even too much!");    } else {	return("Get some more shut eye!");    }};sleepCheck(10);sleepCheck(5);sleepCheck(8);

So here is the code so far.

post-40263-0-54304600-1391899233_thumb.p

I keep getting a syntax error. also sometimes I'll change one thing and it will say numHours is not defined and codecademy says I passed. O.o

If you tell me what's wrong please EXPLAIN WHY!!!! I still want to learn!

 

Thanks in advance!

The year is 20XX. Everyone plays Fox at TAS levels of perfection. Because of this, the winner of a match depends solely on port priority. The RPS metagame has evolved to ridiculous levels due to it being the only remaining factor to decide matches.

Only Abate, Axe, and Wobbles can save us.

Link to comment
Share on other sites

Link to post
Share on other sites

why is there a semicolon next to the bracket at the very top? I'm just learning java but I'm pretty sure you shouldn't do that.

Link to comment
Share on other sites

Link to post
Share on other sites

Look at line 4 in your code. You put a curly brace before the content of the function, which closed it, and then you put a semicolon, which you don't need after a curly brace anyway.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

Look at line 4 in your code. You put a curly brace before the content of the function, which closed it, and then you put a semicolon, which you don't need after a curly brace anyway.

I removed line 4 and line three becomes broken

The year is 20XX. Everyone plays Fox at TAS levels of perfection. Because of this, the winner of a match depends solely on port priority. The RPS metagame has evolved to ridiculous levels due to it being the only remaining factor to decide matches.

Only Abate, Axe, and Wobbles can save us.

Link to comment
Share on other sites

Link to post
Share on other sites

why is there a semicolon next to the bracket at the very top? I'm just learning java but I'm pretty sure you shouldn't do that.

it's not necessary but doesn't change anything. I put it there so the little i doesn't pop up in front of the line

The year is 20XX. Everyone plays Fox at TAS levels of perfection. Because of this, the winner of a match depends solely on port priority. The RPS metagame has evolved to ridiculous levels due to it being the only remaining factor to decide matches.

Only Abate, Axe, and Wobbles can save us.

Link to comment
Share on other sites

Link to post
Share on other sites

So here is the code so far.

attachicon.gifScreenshot 2014-02-08 at 4.37.56 PM.png

I keep getting a syntax error. also sometimes I'll change one thing and it will say numHours is not defined and codecademy says I passed. O.o

If you tell me what's wrong please EXPLAIN WHY!!!! I still want to learn!

 

Thanks in advance!

I believe everything from 'if...' up to but not including 'sleepcheck(8)' (lines 5-10) needs to be inside the curly braces on lines 3 and 4.

the instruction also say to 'return' the statements not console.log() them

 

 

why is there a semicolon next to the bracket at the very top? I'm just learning java but I'm pretty sure you shouldn't do that.

it's javascript, but you are right the semicolon is not needed

I remain,  

msevilgenius

Link to comment
Share on other sites

Link to post
Share on other sites

I removed line 4 and line three becomes broken

put a brace on line 11 and move the current contents of line 11 to a new line. You have opening and closing braces for the if and else, but if you just delete line 4 then you have no closing brace for the function.

 

I'm more familiar with Java and Python than Javascript, so I'm sorry if I'm incorrect. My general knowledge makes me think that's the problem though.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

put a brace on line 11 and move the current contents of line 11 to a new line. You have opening and closing braces for the if and else, but if you just delete line 4 then you have no closing brace for the function.

ok now I get this(sorry for the large pics. Taking screenshots on a cromebook)

post-40263-0-15089200-1391900097_thumb.p

The year is 20XX. Everyone plays Fox at TAS levels of perfection. Because of this, the winner of a match depends solely on port priority. The RPS metagame has evolved to ridiculous levels due to it being the only remaining factor to decide matches.

Only Abate, Axe, and Wobbles can save us.

Link to comment
Share on other sites

Link to post
Share on other sites

Here is my code if you want to see something that should theoretically work:

//Write your function below. //Don't forget to call your function!var sleepCheck = function(numHours) {    if (numHours >= 8){	return("You're getting plenty of sleep! Maybe even too much!");    } else {	return("Get some more shut eye!");    }};sleepCheck(10);sleepCheck(5);sleepCheck(8);

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

 

Here is my code if you want to see something that should theoretically work:

//Write your function below. //Don't forget to call your function!var sleepCheck = function(numHours) {    if (numHours >= 8){	return("You're getting plenty of sleep! Maybe even too much!");    } else {	return("Get some more shut eye!");    }};sleepCheck(10);sleepCheck(5);sleepCheck(8);

Ok so that worked. Now I wan't to know why this worked and mine didn't. 

The year is 20XX. Everyone plays Fox at TAS levels of perfection. Because of this, the winner of a match depends solely on port priority. The RPS metagame has evolved to ridiculous levels due to it being the only remaining factor to decide matches.

Only Abate, Axe, and Wobbles can save us.

Link to comment
Share on other sites

Link to post
Share on other sites

Ok so that worked. Now I wan't to know why this worked and mine didn't. 

It's possible JS is anal about spacing. I seem to recall that being an issue in the past.

if (num<=10){

won't work, but

if (num<=10) {

would. Same goes for spacing after else. "else{" might not work, whereas "else {" would.

 

I think. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Remove the ';' from the end of the if statement. It is not needed.

CPU: i7 4770k | GPU: Sapphire 290 Tri-X OC | RAM: Corsair Vengeance LP 2x8GB | MTB: GA-Z87X-UD5HCOOLER: Noctua NH-D14 | PSU: Corsair 760i | CASE: Corsair 550D | DISPLAY:  BenQ XL2420TE


Firestrike scores - Graphics: 10781 Physics: 9448 Combined: 4289


"Nvidia, Fuck you" - Linus Torvald

Link to comment
Share on other sites

Link to post
Share on other sites

read this post without any of the assumptions/knowledge gained from other posts.

 

1.  you start the 'sleepcheck' function on line 3 and end it on line 4.  the function is empty and literally does nothing.

 

2.  on line 5, you ask a FUNCTION what number it is.  this is a logical issue; you can only ask numbers what number they are.

 

 

this probably won't answer your questions, but if i just gave you all the detailed answers; you probably wouldn't learn anything either.  try asking questions one step at a time.

 

EDIT: 

 

the accepted answer is wrong.  return is a keyword, NOT a function.  there should not be ()s for the 'return' statement.

 

EDIT2:

 

i should clarify what i mean by wrong.  i'm not saying it doesn't work; i'm saying it's not needed, provides NO benefit, will harm your future learning, is NOT standard, and is unnecessarily confusing.  try it without it.

 

also, how are you expected to test your code?  nothing is being outputted.

 

EDIT3:

 

js is very largely space insensitive, especially when you use semicolons correctly.

Link to comment
Share on other sites

Link to post
Share on other sites

Ok so that worked. Now I wan't to know why this worked and mine didn't. 

Starting on line 4, you put:

if (sleepCheck>=8){    console.log("stuff");} else {    console.log("other stuff");}

Two problems here:

  1. The big one is that you have sleepCheck where numHours should be. You want to compare the value of a variable (number of hours of sleep) to 8, but instead you are comparing a function, and on top of that, you are inside the function that you're referencing.
  2. Replace console.log() with return. You want your function to return something. You could console.log() the text and return 0 in a normal program, but Codecademy asks specifically for you to "return" your answer.

That's all I can find right now. If it still doesn't work then let me know :)

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

Starting on line 4, you put:

if (sleepCheck>=8){    console.log("stuff");} else {    console.log("other stuff");}

Two problems here:

  1. The big one is that you have sleepCheck where numHours should be. You want to compare the value of a variable (number of hours of sleep) to 8, but instead you are comparing a function, and on top of that, you are inside the function that you're referencing.
  2. Replace console.log() with return(). You want your function to return something. You could console.log() the text and return 0 in a normal program, but Codecademy asks specifically for you to "return" your answer.

That's all I can find right now. If it still doesn't work then let me know :)

 why do you keep saying return is a function?

 

what language are you used to where return is a function?

Link to comment
Share on other sites

Link to post
Share on other sites

 why do you keep saying return is a function?

 

what language are you used to where return is a function?

I didn't think I ever said that return was a function, just that every function should return some value.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

you're saying it's a function because you call it like a function.

Link to comment
Share on other sites

Link to post
Share on other sites

you're saying it's a function because you call it like a function.

Minor technicality tbh, don't make such a big deal out of it. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

you're saying it's a function because you call it like a function.

"return()" vs "return". I just put the parentheses because if you're returning a string, you need them for return.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

"return()" vs "return". I just put the parentheses because if you're returning a string, you need them for return.

No you don't.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

No you don't.

Ok, then you don't need to. It didn't throw an error in my code above, and I prefer to use parentheses whenever I can (it groups things and makes it easier for me to understand both code and math). I haven't actually used JS in a while so you'll have to forgive minor syntax errors or things I've carried over from other languages.

[spoiler=My Current PC]AMD FX-8320 @ 4.2 Ghz | Xigmatek Dark Knight Night Hawk II | Gigabyte GA-990FXA-UD3 | 8GB Adata XPG V2 Silver 1600 Mhz RAM | Gigabyte 3X Windforce GTX 770 4GB @ 1.27 Ghz/7.25 Ghz | Rosewill Hive 550W Bronze PSU | Fractal Design Arc Midi R2 | Samsung Evo 250 GB SSD | Seagate Barracuda 1TB HDD | ASUS VS239H-P | Razer Deathadder 2013 Partlist

 

LTT Build-Off Thread: http://linustechtips.com/main/topic/35226-the-ltt-build-off-thread-no-building-required/

Link to comment
Share on other sites

Link to post
Share on other sites

that's all i'm saying.  an ounce of prevention is worth 2.4 metric tons of cure when you're learning.  I'm not trying to call you stupid; I just don't see why we should teach people the wrong thing when the correct answer is EASIER and better to do.

 

EDIT:

 

js almost never throws errors.  it's actually quite hard.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×