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