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