← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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