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