← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 18
  2. 90
  3. <script>
  4. let
  5. .js
  6. let
  7. Welcome, Aman!
  8. 44
  9. 70
  10. 36
  11. 32
  12. Well done, Riya!
  13. actions and changes
  14. 41
  15. alert()
  16. 2
  17. console.log()
  18. 27
  19. 20
  20. 49
  21. for
  22. 8
  23. 11
  24. in the console
  25. Welcome, Kabir!
  26. if
  27. 22
  28. 11
  29. 43
  30. 70
  31. Hi, Aman!
  32. Hi, Riya!
  33. 9
  34. Hello, Arjun!
  35. Welcome, Riya!
  36. 57
  37. 82
  38. 28
  39. Well done, Kabir!
  40. 28

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