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