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