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