Easy Javascript questions
You can use window.history to retrieve the history object. Using the history object, what methods can you call to navigate backwards and forward to web pages that have been visited recently? The answer is not in the book. See https://developer.mozilla.org/en-US/docs/Web/API/History.
Think about the situation where the alert message displays “your reply was false.” Describe the type of person who would generate that output—someone who always tells the truth, someone who always lies, or some other type of person?
This code describes how to continue a string with \:
<script> prompt("Of the following U.S. Presidents, which one" + " did not die on July 4?\n \ a) John Adams\n \ b) Thomas Jefferson\n \ c) James Monroe\n \ d) Ronald Reagan", ""); </script>
Provide new code for the first three lines (the first line is <script>) such that you use \ instead of + for the string continuation mechanism. Make sure that the resulting dialog’s message looks the same as the original dialog’s message. Hint: In order to get the resulting message to look good, you might have to compromise your coding style a bit.
Provide an alert method call that shows the code fragment’s effect. Specifically, your alert method call should produce the following dialog. Your code should produce the alert message precisely—don’t forget the spaces, the quotes, the new lines, and so on.
Given the following code fragment. What are the resulting values in var1, var2, var3, var4, and var5?
var name = "Cat in the Hat"; var1 = name.length(); var2 = name.charAt(5); var3 = name.indexOf(" "); var4 = name.indexOf("t", 4); var5 = name.lastIndexOf("t");
Given the following code fragment. What are the resulting values in var1, var2, var3, and var4?
var name = "Anna banana"; var1 = name.substring(4, 8) + " "; var2 = var1.trim(); var3 = name.replace("an", "ri"); var4 = name.substring(5);
How is the label element helpful for web accessibility?
Suppose you have a button that is placed outside of a web page’s form. What’s the best way to associate the button with the form, so that when the user clicks the button, it’s straightforward for the form’s controls to get processed?
Given this code fragment:
if (lineSize) { alert("There are " + lineSize + " people in line."); } else { alert("The line is empty."); }
a) If lineSize is 0, what’s the output?
b) If lineSize is 5, what’s the output?
Sometimes, JavaScript’s == operator is slightly slower than the identity operator. In what situation is that the case?
Assume this:
var x = 15; var y = .4;
Evaluate the following expressions. Show your work, using a separate line for each evaluation step.
a) 4 - x / 2 + y
b) x % 4 + 4 % x
c) 2 ** 3 / 2 * 3
d) y != 0 && !(y > 4 || true)
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Question :
Answer :
prompt("Of the following U.S. Presidents, which one did not die on July 4?\n \
a) John Adams\n \
b) Thomas Jefferson\n \
c) James Monroe\n \
d) Ronald Reagan", "");
Screen :
**********************************
Question :
Answer :
alert("exclamation = \"Holy Cow!\"\nexclamationUpper = \"HOLY COW!\"\nexclamationLower = \"holy cow!\"");
Output Screen :
**********************************
Question :
Answer :Below is the correct code snippet
var name = "Cat in the Hat";
var1 = name.length;
var2 = name.charAt(5);
var3 = name.indexOf(" ");
var4 = name.indexOf("t", 4);
var5 = name.lastIndexOf("t");
document.write("var 1 : "+var1+"<br/>");//display var1
document.write("var 2 : "+var2+"<br/>");//display var2
document.write("var 3 : "+var3+"<br/>");//display var3
document.write("var 4 : "+var4+"<br/>");//display var4
document.write("var 5 : "+var5+"<br/>");//display var5
Screen :Below screen shows the output
**********************************
Question :
Answer :Below is the code snippet
var name = "Anna banana";
var1 = name.substring(4, 8) + " ";
var2 = var1.trim();
var3 = name.replace("an", "ri");
var4 = name.substring(5);
document.write("var 1 : "+var1+"<br/>");//display var1
document.write("var 2 : "+var2+"<br/>");//display var2
document.write("var 3 : "+var3+"<br/>");//display var3
document.write("var 4 : "+var4+"<br/>");//display var4
Screen :
**********************************
Question :
Screen 1:Screen when lineSize=0;
Screen 2 :Screen when lineSize=5;
**********************************
Question :
Answer :Below is the code snippet
var x = 15;
var y = .4;
document.write("a) 4 - x / 2 + y : "+(4 - x / 2 + y)+"<br/>");
document.write("b) x % 4 + 4 % x : "+(x % 4 + 4 % x)+"<br/>");
document.write("c) 2 ** 3 / 2 * 3 : "+(2 ** 3 / 2 * 3)+"<br/>");
document.write("d) y != 0 && !(y > 4 || true): "+(y != 0 && !(y > 4 || true))+"<br/>");
Screen :Below screen shows the output
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Easy Javascript questions You can use window.history to retrieve the history object. Using the history object, what methods can you call to navigate backwards and forward to web pages that have been...