← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. if
  2. 20
  3. alert()
  4. Hi, Meera!
  5. 24
  6. 44
  7. Welcome, Aman!
  8. 9
  9. 33
  10. in the console
  11. 24
  12. let
  13. 0
  14. 77
  15. a pop-up box
  16. 20
  17. Hi, Riya!
  18. 1
  19. 23
  20. 20
  21. Hi, Meera!
  22. 2
  23. 26
  24. 41
  25. <script>
  26. 12
  27. 24
  28. 51
  29. Hello, Kabir!
  30. Hello, Aman!
  31. 28
  32. 11
  33. .js
  34. 55
  35. 18
  36. 14
  37. let
  38. 40
  39. actions and changes
  40. 47

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