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