Can Someone Tell Me Why This Code Doesn't Work?

function bonusTime(salary, bonus) {
if (bonus = true) { return "£" + salary * 10;
} else {return "£" + salary;}
 
}

bonusTime(10000, false);

So I want this function to return the salary * 10 plus the £ sign if the second parameter(value) is true. If the second parameter(value) is false then it should return £ plus the original number, in this case it should return £10000. It keeps returning £100000. It works fine if you pass bonusTime(10000, true);.

Sorry to waste your time. I just figured it out. I needed to change the if statement to (bonus == true).

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums