← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 539 · 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 does this code show?
    let name = "Riya";
    alert("Hello, " + name + "!");
    (a) Riya (b) Hello, name! (c) Hello, Riya! (d) name
  2. 2.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 8;
    console.log(x + y);
    (a) Error (b) 88 (c) 16
  3. 3.⚡ Which JavaScript word writes in the console? (a) if (b) console.log() (c) let (d) alert()
  4. 4.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .jpg (c) .html (d) .js
  5. 5.⚡ What number does this code print?
    let a = 7;
    let b = 8;
    console.log(a * b);
  6. 6.⚡ What does this code show?
    let name = "Zoya";
    alert("Hello, " + name + "!");
    (a) Hello, name! (b) name (c) Zoya (d) Hello, Zoya!
  7. 7.⚡ What does this code show?
    let name = "Riya";
    alert("Hi, " + name + "!");
    (a) Riya (b) Hi, Riya! (c) name (d) Hi, name!
  8. 8.⚡ What number does this code print?
    let apples = 5;
    apples = apples + 12;
    apples = apples - 11;
    console.log(apples);
  9. 9.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) if (c) for (d) let
  10. 10.⚡ What number does this code print?
    let a = 5;
    let b = 12;
    console.log(a * b);
  11. 11.⚡ Which JavaScript word makes a new variable? (a) if (b) console.log() (c) for (d) let
  12. 12.⚡ What number does this code print?
    let apples = 20;
    apples = apples + 6;
    apples = apples - 3;
    console.log(apples);
  13. 13.⚡ What number does this code print?
    let a = 11;
    let b = 28;
    console.log(a + b);
  14. 14.⚡ Which JavaScript word runs code when true? (a) alert() (b) if (c) for (d) console.log()
  15. 15.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 5;
    console.log(x + y);
    (a) 85 (b) 13 (c) Error
  16. 16.⚡ What number does this code print?
    let a = 10;
    let b = 5;
    console.log(a * b);
  17. 17.⚡ Where does console.log() show its output? (a) on the title bar (b) in the address bar (c) on the printer (d) in the console
  18. 18.⚡ What number does this code print?
    let score = 24;
    score = score + 5;
    score = score - 21;
    console.log(score);
  19. 19.⚡ What number does this code print?
    let a = 58;
    let b = 10;
    console.log(a + b);
  20. 20.⚡ What does this code show?
    let name = "Riya";
    console.log("Well done, " + name + "!");
    (a) name (b) Riya (c) Well done, Riya! (d) Well done, name!
  21. 21.⚡ What does alert() show? (a) a table (b) a picture (c) a pop-up box (d) a new tab
  22. 22.⚡ What does this code print? (Look at the quotes!)
    let x = "9";
    let y = 9;
    console.log(x + y);
    (a) Error (b) 18 (c) 99
  23. 23.⚡ What does this code show?
    let name = "Aman";
    alert("Hello, " + name + "!");
    (a) Aman (b) Hello, Aman! (c) Hello, name! (d) name
  24. 24.⚡ What does JavaScript add to a web page? (a) the page title (b) the domain name (c) actions and changes (d) only colours
  25. 25.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 5;
    console.log(x + y);
    (a) 8 (b) 35 (c) Error
  26. 26.⚡ Which JavaScript word repeats code? (a) let (b) alert() (c) for (d) console.log()
  27. 27.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 8;
    console.log(x + y);
    (a) 13 (b) 58 (c) Error
  28. 28.⚡ What number does this code print?
    let books = 14;
    books = books + 4;
    books = books - 8;
    console.log(books);
  29. 29.⚡ What number does this code print?
    let a = 11;
    let b = 2;
    console.log(a * b);
  30. 30.⚡ What number does this code print?
    let a = 5;
    let b = 9;
    console.log(a * b);
  31. 31.⚡ What number does this code print?
    let books = 23;
    books = books + 11;
    books = books - 10;
    console.log(books);
  32. 32.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 1;
    console.log(x + y);
    (a) 6 (b) 51 (c) Error
  33. 33.⚡ What does this code show?
    let name = "Riya";
    alert("Well done, " + name + "!");
    (a) Riya (b) Well done, name! (c) Well done, Riya! (d) name
  34. 34.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 2;
    console.log(x + y);
    (a) 3 (b) 12 (c) Error
  35. 35.⚡ What number does this code print?
    let runs = 25;
    runs = runs + 20;
    runs = runs - 9;
    console.log(runs);
  36. 36.⚡ What number does this code print?
    let a = 37;
    let b = 5;
    console.log(a + b);
  37. 37.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 7;
    console.log(x + y);
    (a) 17 (b) 8 (c) Error
  38. 38.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <js> (c) <code> (d) <style>
  39. 39.⚡ What number does this code print?
    let a = 45;
    let b = 37;
    console.log(a + b);
  40. 40.⚡ What does this code print? (Look at the quotes!)
    let x = "6";
    let y = 3;
    console.log(x + y);
    (a) 9 (b) Error (c) 63

Answer key

  1. Hello, Riya!
  2. 88
  3. console.log()
  4. .js
  5. 56
  6. Hello, Zoya!
  7. Hi, Riya!
  8. 6
  9. alert()
  10. 60
  11. let
  12. 23
  13. 39
  14. if
  15. 85
  16. 50
  17. in the console
  18. 8
  19. 68
  20. Well done, Riya!
  21. a pop-up box
  22. 99
  23. Hello, Aman!
  24. actions and changes
  25. 35
  26. for
  27. 58
  28. 10
  29. 22
  30. 45
  31. 24
  32. 51
  33. Well done, Riya!
  34. 12
  35. 36
  36. 42
  37. 17
  38. <script>
  39. 82
  40. 63

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