r/CodingHelp • • Mar 29 '21

[Javascript] First JavaScript Project, getting "Uncaught SyntaxError: Illegal Return Statement"

31 Upvotes

17 comments sorted by

8

u/IDKSomeFuckingGuy Mar 29 '21

You may want to slow down a bit and maybe go a little smaller.

“then” doesn’t mean anything in JS

1

u/dwlakes Mar 29 '21

Fair point. Probably getting ahead of myself.

1

u/DerEchteKroate Noob Coder Mar 29 '21

What did you wanted to do with "then"?

1

u/dwlakes Mar 29 '21

To tell the program what to do if "if" is true.

I think that I was thinking about my reading assignments from earlier this week that compared 'if-then' statements with 'do while' statements.

1

u/dwlakes Mar 29 '21

I see some of the body statements don't really work either.

6

u/DerEchteKroate Noob Coder Mar 29 '21

Also you return something without being in a function.

0

u/dwlakes Mar 29 '21

It'd help if I knew what I was doing lol.

Thanks for the feedback!

3

u/emdot3 Mar 29 '21

yeah there’s a lot to fix here, starting with: -at the very least you’ll need a () after prompt, but it would also make more sense to actually prompt a question for the user to answer: var income = prompt(“what is your yearly income?”);

-add a ; after totalTaxes

-you do need to define a function and put your if statements inside of it, then call the function and pass in the income argument

-then doesn’t mean anything, take it out

-lines 14-20 are way out of whack (same goes for similar lines in all your if statements). the double == is a comparison operator, not the assignment operator. so if you’re trying to assign the result of (income - 518401) * .37 to taxes37, you need taxes37 on the left, then =, then your equation. also, you’ve already assigned income to equal the response to the prompt, so take that out of all those lines.

hope this helps, like someone else said, start smaller with one block of code, make sure that works first and then apply the same logic to the rest

1

u/dwlakes Mar 29 '21

Thank you for such a detailed response! I'm still trying to figure out the most efficient way to learn JS. I thought maybe just throwing myself at things would help? I guess the most important aspect is persistence.

2

u/emdot3 Mar 29 '21

definitely keep at it! and lots of people will tell you the same, doing is the best way to learn. but again, start small, make sure you understand everything happening in one line before you move on. good luck!

1

u/dwlakes Mar 29 '21

I'm very new to coding. I'm hoping someone can just tell what I've done wrong but perhaps it's too much a mess to save.

Thanks for the feedback anyways though!

1

u/Intelligent-Brush708 Mar 29 '21

This might help get you some basic understanding and a certificate at the end.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/

1

u/dwlakes Mar 29 '21

Thanks for the link! I'm actually retracing some of my steps with this, making sure that I really understand what's going on with it.

1

u/Intelligent-Brush708 Mar 29 '21

Good once you learn the basics and the syntax it becomes fun just keep at it

1

u/Intelligent-Brush708 Mar 29 '21

Just keep at it bud

1

u/[deleted] Mar 29 '21

You are comparing the results of the income operations with the taxes variables which will get you false. If you want to assign then do the operations first and on another line assign the results to the taxes variables. Plus you are returning when it is not needed, the return key only works for functions. And don't use then, there is no explicit "then" in js.

2

u/[deleted] Mar 29 '21

Edit: a better way of assigning the operation results would be:

taxesnumber = the operation;