← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 64 · 40 questions
TalentJR

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

Answer key

  1. 19
  2. 15
  3. 28
  4. alert()
  5. if
  6. console.log()
  7. a pop-up box
  8. Hi, Riya!
  9. let
  10. Welcome, Aman!
  11. .js
  12. 96
  13. Hello, Riya!
  14. in the console
  15. 11
  16. for
  17. Hello, Zoya!
  18. 15
  19. 20
  20. let
  21. 4
  22. 55
  23. 31
  24. 53
  25. actions and changes
  26. 6
  27. Hello, Meera!
  28. 94
  29. 46
  30. Welcome, Riya!
  31. 9
  32. 29
  33. 61
  34. Hi, Arjun!
  35. 0
  36. 12
  37. 29
  38. 47
  39. 40
  40. 49

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids