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