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