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