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