JavaScript Coding for Kids 1 — Questions and Answers
Question 1: What is the correct JavaScript syntax for modifying the HTML element below?
- document.getElement("p").inner= "Hello World!;
- #demo.innerHTML = "Hello World!";
- document.getElementByName('= "Hello World!";
- document.getElementById("demo").innerHTML = "Hello World!"; (Correct answer)
Correct answer: document.getElementById("demo").innerHTML = "Hello World!";
This is the correct JavaScript syntax for accessing an HTML element by its unique ID and modifying its content. `document.getElementById("demo")` targets the specific HTML element that has the `id="demo"` attribute. The `.innerHTML = "Hello World!";` part then assigns the string "Hello World!" as the new HTML content inside that element.
Question 2: How do you declare a variable in JavaScript?
- variable carName;
- var carName; (Correct answer)
- v carName;
- define carName
Correct answer: var carName;
The `var` keyword is the traditional way to declare a variable in JavaScript. When you write `var carName;`, you are telling the JavaScript engine to create a variable named `carName`. While modern JavaScript also uses `let` and `const` for variable declaration, `var` remains a valid and fundamental method.
Question 3: In javascript, which operator is used to assign a value to a variable?
- "
- = (Correct answer)
- X
- *
Correct answer: =
The `=` (equals sign) is the assignment operator in JavaScript. Its purpose is to assign the value on its right-hand side to the variable specified on its left-hand side. For instance, `let score = 100;` uses the `=` operator to store the value `100` into the variable `score`.
Question 4: What is the output of the following program in javascript if the value of x is 40?
- ReferenceError
- Divisible by 10 (Correct answer)
- Divisible by 12
- None of the above
Correct answer: Divisible by 10
Without the specific program code, it's inferred that the program checks for divisibility. If `x` is 40, then 40 is perfectly divisible by 10, as 40 divided by 10 equals 4 with no remainder. Therefore, if the program includes a check for divisibility by 10, 'Divisible by 10' would be the correct output.
Question 5: What language determines a website's behavior?
- HTML
- XML
- CSS
- Java Script (Correct answer)
Correct answer: Java Script
JavaScript is the programming language that dictates a website's behavior and interactivity. While HTML provides the structure and CSS handles the styling, JavaScript enables dynamic features such as user interaction, animations, data manipulation, and communication with web servers. It brings web pages to life by allowing them to respond to events and perform complex operations.
What is the correct JavaScript syntax for modifying the HTML element below?