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