← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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