JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
-
1.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 7;
console.log(x + y); (a) 16 (b) Error (c) 97 - 2.⚡ Which word makes a new variable? (a) give (b) let (c) make (d) put
-
3.⚡ What does this code show?
let name = "Meera";
alert("Hi, " + name + "!"); (a) Hi, name! (b) Meera (c) name (d) Hi, Meera! - 4.⚡ Which JavaScript word writes in the console? (a) alert() (b) console.log() (c) let (d) if
- 5.⚡ Which JavaScript word runs code when true? (a) let (b) if (c) for (d) alert()
-
6.⚡ What number does this code print?
let apples = 23;
apples = apples + 8;
apples = apples - 13;
console.log(apples); -
7.⚡ What number does this code print?
let books = 10;
books = books + 17;
books = books - 21;
console.log(books); -
8.⚡ What number does this code print?
let a = 60;
let b = 10;
console.log(a + b); - 9.⚡ Which JavaScript word shows a pop-up box? (a) let (b) alert() (c) if (d) for
-
10.⚡ What number does this code print?
let runs = 16;
runs = runs + 3;
runs = runs - 12;
console.log(runs); -
11.⚡ What number does this code print?
let a = 9;
let b = 11;
console.log(a * b); -
12.⚡ What number does this code print?
let a = 38;
let b = 6;
console.log(a - b); -
13.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 4;
console.log(x + y); (a) 84 (b) 12 (c) Error -
14.⚡ What does this code show?
let name = "Kabir";
alert("Well done, " + name + "!"); (a) Kabir (b) name (c) Well done, name! (d) Well done, Kabir! -
15.⚡ What number does this code print?
let a = 7;
let b = 8;
console.log(a + b); -
16.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 6;
console.log(x + y); (a) Error (b) 56 (c) 11 -
17.⚡ What does this code show?
let name = "Riya";
console.log("Well done, " + name + "!"); (a) name (b) Well done, name! (c) Riya (d) Well done, Riya! -
18.⚡ What number does this code print?
let a = 39;
let b = 14;
console.log(a + b); - 19.⚡ Which JavaScript word makes a new variable? (a) for (b) alert() (c) console.log() (d) let
-
20.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 1;
console.log(x + y); (a) Error (b) 2 (c) 11 - 21.⚡ Which JavaScript word repeats code? (a) console.log() (b) if (c) alert() (d) for
-
22.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 1;
console.log(x + y); (a) 31 (b) Error (c) 4 -
23.⚡ What number does this code print?
let books = 8;
books = books + 18;
books = books - 12;
console.log(books); - 24.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <code> (c) <style> (d) <js>
-
25.⚡ What does this code show?
let name = "Zoya";
console.log("Hi, " + name + "!"); (a) name (b) Zoya (c) Hi, Zoya! (d) Hi, name! - 26.⚡ What does JavaScript add to a web page? (a) the page title (b) only colours (c) the domain name (d) actions and changes
-
27.⚡ What number does this code print?
let coins = 19;
coins = coins + 4;
coins = coins - 21;
console.log(coins); -
28.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 1;
console.log(x + y); (a) Error (b) 8 (c) 71 -
29.⚡ What does this code show?
let name = "Zoya";
console.log("Welcome, " + name + "!"); (a) Welcome, name! (b) Zoya (c) Welcome, Zoya! (d) name -
30.⚡ What number does this code print?
let a = 46;
let b = 19;
console.log(a + b); -
31.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 4;
console.log(x + y); (a) Error (b) 44 (c) 8 -
32.⚡ What does this code show?
let name = "Arjun";
console.log("Well done, " + name + "!"); (a) Well done, Arjun! (b) Arjun (c) Well done, name! (d) name -
33.⚡ What number does this code print?
let a = 19;
let b = 16;
console.log(a - b); -
34.⚡ What number does this code print?
let marks = 15;
marks = marks + 2;
marks = marks - 1;
console.log(marks); -
35.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) Error (b) 3 (c) 21 -
36.⚡ What number does this code print?
let score = 20;
score = score + 3;
score = score - 12;
console.log(score); -
37.⚡ What number does this code print?
let marks = 21;
marks = marks + 2;
marks = marks - 22;
console.log(marks); -
38.⚡ What number does this code print?
let runs = 17;
runs = runs + 7;
runs = runs - 17;
console.log(runs); - 39.⚡ Where does console.log() show its output? (a) in the console (b) in the address bar (c) on the printer (d) on the title bar
-
40.⚡ What number does this code print?
let coins = 21;
coins = coins + 5;
coins = coins - 21;
console.log(coins);
Answer key
- 97
- let
- Hi, Meera!
- console.log()
- if
- 18
- 6
- 70
- alert()
- 7
- 99
- 32
- 84
- Well done, Kabir!
- 15
- 56
- Well done, Riya!
- 53
- let
- 11
- for
- 31
- 14
- <script>
- Hi, Zoya!
- actions and changes
- 2
- 71
- Welcome, Zoya!
- 65
- 44
- Well done, Arjun!
- 3
- 16
- 21
- 11
- 1
- 7
- in the console
- 5
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids