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