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 number does this code print?
let books = 14;
books = books + 2;
books = books - 16;
console.log(books); -
2.⚡ What number does this code print?
let a = 5;
let b = 4;
console.log(a * b); -
3.⚡ What number does this code print?
let a = 12;
let b = 12;
console.log(a * b); -
4.⚡ What number does this code print?
let coins = 23;
coins = coins + 13;
coins = coins - 29;
console.log(coins); - 5.⚡ Which JavaScript word writes in the console? (a) alert() (b) let (c) for (d) console.log()
-
6.⚡ What number does this code print?
let books = 24;
books = books + 13;
books = books - 30;
console.log(books); -
7.⚡ What number does this code print?
let runs = 8;
runs = runs + 12;
runs = runs - 12;
console.log(runs); - 8.⚡ Which JavaScript word shows a pop-up box? (a) for (b) alert() (c) console.log() (d) let
-
9.⚡ What number does this code print?
let a = 2;
let b = 4;
console.log(a * b); -
10.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) 3 (b) Error (c) 21 -
11.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 8;
console.log(x + y); (a) Error (b) 17 (c) 98 - 12.⚡ Which JavaScript word runs code when true? (a) alert() (b) if (c) for (d) let
-
13.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) Hi, Kabir! (b) name (c) Hi, name! (d) Kabir -
14.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 4;
console.log(x + y); (a) 6 (b) 24 (c) Error - 15.⚡ Which word makes a new variable? (a) put (b) make (c) let (d) give
-
16.⚡ What does this code show?
let name = "Aman";
console.log("Hello, " + name + "!"); (a) Aman (b) Hello, Aman! (c) Hello, name! (d) name -
17.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 5;
console.log(x + y); (a) 15 (b) Error (c) 6 -
18.⚡ What does this code show?
let name = "Arjun";
alert("Well done, " + name + "!"); (a) Well done, name! (b) Arjun (c) Well done, Arjun! (d) name - 19.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <code> (d) <script>
-
20.⚡ What number does this code print?
let a = 20;
let b = 5;
console.log(a + b); - 21.⚡ Where does console.log() show its output? (a) on the printer (b) on the title bar (c) in the address bar (d) in the console
-
22.⚡ What does this code show?
let name = "Riya";
alert("Hi, " + name + "!"); (a) name (b) Hi, name! (c) Riya (d) Hi, Riya! -
23.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 2;
console.log(x + y); (a) 82 (b) 10 (c) Error -
24.⚡ What number does this code print?
let score = 24;
score = score + 10;
score = score - 16;
console.log(score); -
25.⚡ What number does this code print?
let marks = 30;
marks = marks + 13;
marks = marks - 33;
console.log(marks); -
26.⚡ What number does this code print?
let books = 11;
books = books + 5;
books = books - 10;
console.log(books); -
27.⚡ What does this code show?
let name = "Arjun";
console.log("Hello, " + name + "!"); (a) Arjun (b) Hello, Arjun! (c) Hello, name! (d) name -
28.⚡ What does this code show?
let name = "Aman";
console.log("Welcome, " + name + "!"); (a) Welcome, name! (b) name (c) Aman (d) Welcome, Aman! - 29.⚡ Which JavaScript word repeats code? (a) alert() (b) for (c) console.log() (d) let
-
30.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 2;
console.log(x + y); (a) Error (b) 8 (c) 62 - 31.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .js (c) .html (d) .css
-
32.⚡ What does this code show?
let name = "Riya";
console.log("Hello, " + name + "!"); (a) Hello, Riya! (b) Hello, name! (c) name (d) Riya -
33.⚡ What number does this code print?
let a = 4;
let b = 7;
console.log(a * b); -
34.⚡ What number does this code print?
let a = 32;
let b = 8;
console.log(a - b); -
35.⚡ What does this code show?
let name = "Riya";
alert("Hello, " + name + "!"); (a) Riya (b) Hello, Riya! (c) Hello, name! (d) name -
36.⚡ What number does this code print?
let a = 11;
let b = 3;
console.log(a * b); -
37.⚡ What number does this code print?
let a = 29;
let b = 21;
console.log(a + b); -
38.⚡ What number does this code print?
let apples = 26;
apples = apples + 16;
apples = apples - 22;
console.log(apples); -
39.⚡ What number does this code print?
let coins = 6;
coins = coins + 15;
coins = coins - 8;
console.log(coins); -
40.⚡ What number does this code print?
let books = 21;
books = books + 11;
books = books - 9;
console.log(books);
Answer key
- 0
- 20
- 144
- 7
- console.log()
- 7
- 8
- alert()
- 8
- 21
- 98
- if
- Hi, Kabir!
- 24
- let
- Hello, Aman!
- 15
- Well done, Arjun!
- <script>
- 25
- in the console
- Hi, Riya!
- 82
- 18
- 10
- 6
- Hello, Arjun!
- Welcome, Aman!
- for
- 62
- .js
- Hello, Riya!
- 28
- 24
- Hello, Riya!
- 33
- 50
- 20
- 13
- 23
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids