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