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