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