WARNING: This program has a bug, which means we need to fix it!
RULE: If a variable was created outside an event or function, we need to make it a global variable before changing its value inside an event or function. Check the toolkit to find Global Variable.
Click Run and read the error message.
Debug this program by making score a global variable in the click event.
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background_color("black")
score = 0
colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
score_text = codesters.Text("Score: " + str(score), 0, 175, "red")
title_text = codesters.Text("Speed Click Challenge!", 0, 200, "yellow")
circle = codesters.Circle(0, 0, 100, "yellow")
circle.say("Click me as much as possible in 5 seconds!", 3)
def click(sprite):
score += 1
score_text.set_text("Score: " + str(score))
circle.event_click(click)
stage.wait(5)
circle.say("Time's up!")
t = codesters.Teacher()
globals_ = t.find_text("global")
try:
tval1 = globals_[0][1].lower().replace(' ','')
tval1_indent = t.get_indent_at_line(globals_[0][0])
except:
tval1 = "DNE"
tval1_indent = "DNE"
t1 = TestObjective()
t1.add_success('globalscore' in tval1 and tval1_indent == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add Global Variable inside the click event?")
t1.add_failure(tval1 != "DNE" and 'score' not in tval1, "Make sure you're making score the global variable!")
t1.add_failure(tval1 != "DNE" and tval1_indent != 4, "Make sure the Global Variable is indented inside the click event!")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.