focus blur mouseup keyupAnswer:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test Input Events</title> <script> function blurListener( ) { var para1 = document.getElementById("output"); para1.innerHTML += "blur event occurred<br>"; } function focusListener( ) { var para1 = document.getElementById("output"); para1.innerHTML += "focus event occurred<br>"; } function keyUpListener( ) { var para1 = document.getElementById("output"); para1.innerHTML += "keyup event occurred<br>"; } function mouseUpListener( ) { var para1 = document.getElementById("output"); para1.innerHTML += "mouseup event occurred<br>"; } function init( ) { var txtField = document.getElementById("input1"); txtField.addEventListener("blur", blurListener) txtField.addEventListener("focus", focusListener) txtField.addEventListener("mouseup", mouseUpListener) txtField.addEventListener("keyup", keyUpListener) } window.addEventListener("load", init); </script> </head> <body> <h1>Test Input Events</h1> <p>Test events: blur focus mouseup keyup</p> <input type="text" id="input1"><br><br> <p id="output"></p> </body> </html>
function makeGreeting(name) { var greeting = `Hello, ${name}, how are you?`; return greeting } document.writeln(greeting);The variable greeting does not exist after the end of the function.
{ let x = 1.5; x++; } document.writeln(x);These statements generate an error because the variable x does not exist after the block in which it is defined ends.
// Compute the sum of numbers between // 1 and n inclusive: function sum1ToN(n) { var sum = 0; for(let i = 1; i <= n; i++) { sum += i; } return sum; } document.writeln("Sum: " + sum1ToN(100)); // Output: 5050 // Note: a more efficient way to compute // the sum of the numbers from 1 to 100 // is to use this formula: // sum = (n * (n + 1)) / 2 = (100 * 101) / 2 = 10100 / 2 = 5050This last formula is part of a story about the famous mathematician Karl Gauss. When he was in elementary school (some versions of this story say Kindergarten), the teacher asked the class asked the students to add up the numbers from 1 to 100. Although this would be a difficult problem for most elementary school students, Karl Gauss noticed that
sum = 1 + 2 + 3 + ... + 98 + 99 + 100 = (1 + 100) + (2 + 99) + (3 + 98) + ... + (50 + 51) = 101 * 50 = 5050and announced the answer of 5,050 in less than one minute.
let x = prompt("Enter a positive integer."); if (x % 2 == 0) { let parity = "even"; } else { let parity = "odd"; } document.writeln(`Parity: ${parity}`);
var n = 3; function f( ) { var n = 5; document.writeln(n + "<br>"); } document.writeln(n)Explain this output.
"use strict";