← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 18
  2. 50
  3. if
  4. let
  5. 47
  6. Well done, Riya!
  7. a pop-up box
  8. 14
  9. let
  10. <script>
  11. Hi, Arjun!
  12. console.log()
  13. 72
  14. 25
  15. actions and changes
  16. alert()
  17. 6
  18. 43
  19. 23
  20. 58
  21. 97
  22. 6
  23. for
  24. 15
  25. in the console
  26. 94
  27. 18
  28. 31
  29. 29
  30. Well done, Kabir!
  31. Hi, Aman!
  32. Welcome, Aman!
  33. 36
  34. 81
  35. 23
  36. 4
  37. .js
  38. 28
  39. Welcome, Zoya!
  40. 39

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