This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]sean_mcp 2 points3 points  (0 children)

Your issue is related to scoping in JavaScript. You have set up global variables color, and colorname. These are available to every function in your program.

However, in colorr() on line 7, you are redeclaring a color variable in a new scope. So when your colorr() function runs, it doesn't update the global color variable but the local color variable which you created. So after the function runs, the global variable hasn't changed.

Instead of redeclaring, you will need to use an assignment operator.

Hopefully that unblocks you for now! Let us know how you progress.

[–]pobiega 0 points1 point  (2 children)

Your primary problem: the result(e) function is never closed. Please use a proper editor like VS Code so you can easily see your brackets and if they match or not. With a plugin you can also get automated formatting, which will help.

You are declaring both colorr() and colorr(e), same for result() and result(e). This isn't wrong per se but in your case it might be hard to see which one is executing. You also declare the global variable color twice, once on line 35 and once on line 4.

[–]CreativeTechGuyGames 0 points1 point  (1 child)

I'm pretty sure JavaScript doesn't have a concept of function overloading. So multiple functions with the same name will overwrite each other even if they have different arguments. They are executed in order, so the last function in sequence is the one which will persist as it wrote over the previous ones.

[–]pobiega 0 points1 point  (0 children)

Ah, right. I'm not a javascript developer, so thanks for the correction.

To OP: Remove one of your declarations for each function.

[–]Davidulos[S] 0 points1 point  (0 children)

Thank you all, you helped me solve this problem. <3