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