0
0
Javascriptprogramming~10 mins

Global scope in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a global variable named count with value 10.

Javascript
var [1] = 10;
Drag options to blanks, or click blank then click option'
Acount
Blet
Cvar
D10
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a keyword like 'let' or 'var' as the variable name.
Putting the value where the variable name should be.
2fill in blank
medium

Complete the code to access the global variable score inside the function and print it.

Javascript
var score = 5;
function showScore() {
  console.log([1]);
}
showScore();
Drag options to blanks, or click blank then click option'
Ascore
Bvar
Cconsole
D5
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Trying to redeclare the variable inside the function.
Using the keyword 'var' inside console.log.
3fill in blank
hard

Fix the error in the code so the global variable name is updated inside the function.

Javascript
var name = 'Alice';
function changeName() {
  [1] = 'Bob';
}
changeName();
console.log(name);
Drag options to blanks, or click blank then click option'
Alet name
Bconst name
Cvar name
Dname
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Redeclaring the variable inside the function with var, let, or const.
Trying to update the variable without assigning a value.
4fill in blank
hard

Fill both blanks to create a global variable total and update it inside the function.

Javascript
[1] total = 0;
function addFive() {
  total [2]= 5;
}
addFive();
console.log(total);
Drag options to blanks, or click blank then click option'
Avar
B+
C+=
Dlet
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using let instead of var for global variable declaration.
Using + instead of += inside the function.
5fill in blank
hard

Fill all three blanks to create a global variable counter, increment it inside the function, and print it.

Javascript
[1] counter = 1;
function increment() {
  counter [2]= 1;
  console.log([3]);
}
increment();
Drag options to blanks, or click blank then click option'
Avar
Bcounter
C+=
Dlet
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using let instead of var for global variable.
Using + instead of += for increment.
Printing a wrong variable name.