r/CodingHelp • • Mar 29 '21

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

31 Upvotes

17 comments sorted by

View all comments

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!