← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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