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