Complete the code to declare a global variable named count with value 10.
var [1] = 10;
The keyword var declares a variable, and count is the variable name. So var count = 10; creates a global variable named count with value 10.
Complete the code to access the global variable score inside the function and print it.
var score = 5; function showScore() { console.log([1]); } showScore();
The global variable score can be accessed inside the function by its name score. So console.log(score); prints the value 5.
Fix the error in the code so the global variable name is updated inside the function.
var name = 'Alice'; function changeName() { [1] = 'Bob'; } changeName(); console.log(name);
To update the global variable name, just assign a new value to name inside the function without redeclaring it. Using name = 'Bob'; changes the global variable.
Fill both blanks to create a global variable total and update it inside the function.
[1] total = 0; function addFive() { total [2]= 5; } addFive(); console.log(total);
let instead of var for global variable declaration.+ instead of += inside the function.var total = 0; declares a global variable. Inside the function, total += 5; adds 5 to the current value of total.
Fill all three blanks to create a global variable counter, increment it inside the function, and print it.
[1] counter = 1; function increment() { counter [2]= 1; console.log([3]); } increment();
let instead of var for global variable.+ instead of += for increment.var counter = 1; declares a global variable. Inside the function, counter += 1; increases it by 1. Then console.log(counter); prints the updated value.