Question

Easy Javascript questions

  1. 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.

  2. 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?

  3. 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.

  4. 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.

    localhost:57507 says: exclamation-Holy Cow! exclamationUpper HO exclamationLower holy cow! LY cOW! Prevent this page fr

  5. 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");
  6. 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);
  7. How is the label element helpful for web accessibility?

  8. 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?

  9. 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?

  10. Sometimes, JavaScript’s == operator is slightly slower than the identity operator. In what situation is that the case?

  11. 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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 :

7JSDemo.html File| C:/wamp64/www/7JSDemo.html <- +X This page says Of the following U.S. Presidents, which one did not die on

**********************************

Question :

Answer :

alert("exclamation = \"Holy Cow!\"\nexclamationUpper = \"HOLY COW!\"\nexclamationLower = \"holy cow!\"");

Output Screen :

localhost8080/7JSDemo.html + U × ぐ→ × ⓘ localhost:8080/7JSDemo.html localhost:8080 says exclamation Holy Cow! exclamationUpp

**********************************

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

localhost:8080/7JSDemo.html x+ localhost:8080/7JSDemo.html var1 14 vaf var 3: 3 var 4:7 var 5:13

**********************************

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 :

localhost:8080/7JSDemo.htmx+ localhost:8080/7JSDemo.html var 1 : barn vaf var 3: Anna briana var 4 banana

**********************************

Question :

Screen 1:Screen when lineSize=0;

C localhost808or7SDermo.html × → × ⓘ localhost8080/7JSDermo.html localhost:8080 says .lhe line is emlíy. OK

Screen 2 :Screen when lineSize=5;

localhost.8080/75Dema.htm+ → × ⓘ localhost8080/7JSDermo.html localhost:8080 says There are 5 people in line. OK

**********************************

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

localhost:8080/7JSDemo.html x+ 4 C localhost:8080/7JSDemo.html a)4-x/2+y:-31 b) x 0 0 4 + 4 % x : 7 c)2 3/2 3 12

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT