If equal statement accepting other numbers?

If equal statement accepting other numbers?


I’m not sure what I’m doing wrong if you guys can clarify that’d be great! Don’t spoil the challenge for me! Take a look at my code on the right. My if statement says to return name[0] (“Hole-in-one!”) if stroke = 1, although when i plug in 3 i still get name[0] and I’m not sure why.

if stroke == 1 and stroke(3) then i get my else statement “what?”
if stroke >= 1 and stroke(3) I get my else statement again

but when i use “= 1” values above 1 are accepted, why?


In the future, instead of using screenshots, try to paste actual code. That makes it easier for us to test your code and highlight the code in replies to make references to it.

Anyway, to answer your question:

When you write the following if statement, you should be using a comparison operator such as === instead of the assignment operator =.

if (stroke = 1) { 

What is actually happening above is you are assigning the number 1 to the stroke variable. So basically, the if statement is the same as:

if (1) {

Any number that is not the value 0 gets evaluated as true, so your fisrt function returns “Hole-in-one!” as long as stroke is not 0.

In your 4th function, your if statement below tests if strokes is equal to 1. Because you pass in the value 3 to the function, 3 is not equal to 1, so your else statement executes and returns " what?".

I do not see any function shown in your screenshot where you test if stroke >=1, so I can not comment on why it does anything. Please copy/paste the related function in a reply, so I can give you feedback.


Ahhhhh I understand thank you!