← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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