Question

Tip Calculator The code works, but has significant errors when placed in a validator. Can you...

Tip Calculator

The code works, but has significant errors when placed in a validator. Can you provide code that will clear the validation process without error? The validator does not like the "out', indicated it was not defined, then the string of code is bringing up several errors with "stray tag".

It has to show no errors, here are the a few coming up, could not post all:

table.js

out = " Price15 %18%20%";

document.writeln(out);

var a, b, c;

for(var x = 8 ; x <= 25 ; x++)

{

a = x * 0.15;

b = x * 0.18;

c = x * 0.20;

out = " "+x+""+a.toFixed(2)+""+b.toFixed(2)+""+c.toFixed(2)+"";

document.writeln(out);

}

table.php

<!DOCTYPE html>

<html>

<head>

<title>Table Application</title>

</head>

<body>

<h1 align="center">Tip Calculator</h1>

<table border="2px" align="center">

<script type="text/javascript" src="table.js">

</script>

</table>

</body>

</html>

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

For your file table.js:

1. Certain Javascript validators do not allow a global variable to be declared without the 'var' keyword. You can try adding the 'var' keyword in order to remove the validation error on the 'out' variable that you have declared.

2. Since the toFixed() function in javascript converts the decimal value to a string in up to the specified decimal values, you can avoid using multiple "" empty string quotes.

So your table.js should now look something like this:

var out = " Price15 %18%20%";

document.writeln(out);

var a, b, c;

for(var x = 8 ; x <= 25 ; x++)

{

a = x * 0.15;

b = x * 0.18;

c = x * 0.20;

out = " "+x+a.toFixed(2)+b.toFixed(2)+c.toFixed(2);

document.writeln(out);

}

Now coming to your file table.php:

1. The align attribute is not supported in HTML5 for both the <h1> tag and <table> tag. Also, the border attribute for table tag. Hence, it is always better to use CSS styling for the same.

So you table.php file should look like this:

<!DOCTYPE html>

<html>

<head>

<title>Table Application</title>

</head>

<body>

<h1 style="text-align:center;">Tip Calculator</h1>

<table style="text-align:center; border:2px;">

<script type="text/javascript" src="table.js">

</script>

</table>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
Tip Calculator The code works, but has significant errors when placed in a validator. Can you...
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
  • could you please show me what I am doing wrong in the Javascript code below. <html>...

    could you please show me what I am doing wrong in the Javascript code below. <html>   <head> <meta charset="UTF-8"> <title></title> <style> #mytext { color: white; text-align: center; } </style> <script> var words = "The cat sat on the mat"; document.writeln("id='mytext"+ words '); </script>   </head>   <body>   </body> </html>

  • Trying to understand java script.. The code provided prints out a game board of cells that...

    Trying to understand java script.. The code provided prints out a game board of cells that are 10 x 10.   I currnetly have it printed out so that it will print out pink squares. how can i create a click even on any of the pink squares that when they are clicked it will turn the square black...   then any square that is black when it is clicked it will change back to the color pink html/js code and css...

  • In this Javascript code, why are 2 for loops needed? could you please explain this to...

    In this Javascript code, why are 2 for loops needed? could you please explain this to me. This is the outcome * ** *** **** ***** ****** ******* ******** ********* the code is <html> <head>               <title></title>        <script>                  showStars(10);               function showStars(rows){            for(var i = 0; i < rows; i++){                var pattern = "";                for(var j...

  • Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an...

    Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an alert if the value of my selection is "0". I will be using this for a validation form assignement. So if the user leaves the selection on the default "0" value I can prompt the user to pick a valid option which would be 1+. Not sure how to access this value. Example code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Form Validation</title>...

  • Create an HTML form that takes these inputs: Number of rows, and number of columns. This...

    Create an HTML form that takes these inputs: Number of rows, and number of columns. This form will submit to a PHP page. Create that page that will accept input from the HTML form and generates the table from the user's input. I already have the portion that generates the table based on user input by using Javascript in an HTML page, I just need to know how to generate the table using a PHP page instead. Here's the code...

  • Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum...

    Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1.      Open the HTML and JavaScript files below: 2.      In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...

  • This question relates to Javascript. Could you please show me why my code is not working?...

    This question relates to Javascript. Could you please show me why my code is not working? I want to create 2 text boxes and have the user enter something into both of them. If the text entered into both boxes is identical the a green message is made visible. If the boxes are different a red message is made visable. Please keep it simple because I am new to javascript. <html> <head>               <title></title>        <script>...

  • Form for a user to enter billing and shipping information. A checkbox that when clicked copies...

    Form for a user to enter billing and shipping information. A checkbox that when clicked copies all of the billing information to the shipping information. A submit button that, when clicked, will make sure that all text fields have had data entered into them. Create your own validation in for the fields, No automatic browser validation. JavaScript/HTML <!DOCTYPE html> <html lang="en"> <head> </head> <body>    <div class="container">       <header>          <h1>                      </h1>       </header>       <nav>          <ul>...

  • I need to complete 3 validation cases in this Javascript code. I need to validate email,...

    I need to complete 3 validation cases in this Javascript code. I need to validate email, phone and street address. How would I go about validating these 3 cases in this code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Week 10: Regular Expressions</title> <style type="text/css"> span { padding: 2px; } .success { color: #008000; background: #99cc99; } .failure { color: #ff0000; background: #ff9999; } </style> <script type="text/javascript"> function validateInput(form) { var result0 = document.getElementById('result0'), result1 = document.getElementById('result1'), result2 = document.getElementById('result2'),...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

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