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