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