Visitor Counter
JavaScript
20 pts
Visitor Counter
The Keren school library counts its visitors. The starter has a global variable let visitors = 0;.
- Write
addVisitor(name): it adds 1 to the globalvisitorsand returns a line likeSelam is visitor number 1. - Write
resetVisitors(): it sets the globalvisitorsback to 0.
Inside the functions, change the global variable — do not write let visitors again (that would make a new local variable). The starter prints:
Selam is visitor number 1 Abel is visitor number 2 Ruta is visitor number 3 Total: 3
Checklist
- Write
addVisitor(name)that counts up the global variable and returns the line. - Write
resetVisitors()that sets the counter back to 0. - Change the global
visitors; never declare it again inside a function. - The four lines are printed.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
