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