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