QUESTION IMAGE
Question
- \you win!\ never displays. what line is responsible for this error? var score = 0; onevent(\button2\, \click\, function() { var score = score + 1; if(score > 5) { settext(\display\, \you win!\); } }); 1 3 4 5
Step1: Analyze variable scope
In line 3, var score = score + 1; creates a new local variable score within the function. This local score shadows the global score declared in line 1.
Step2: Check condition evaluation
The if (score > 5) in line 4 uses the local score (initialized to 1 each time the function runs due to var score = score + 1;). So, it never exceeds 5.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
3