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