Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

7) \you win!\ never displays. what line is responsible for this error? …

Question

  1. \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

Explanation:

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.

Answer:

3