Write a function that returns the total cost of any number of
buckets of paint. Ask the user how many buckets he or she is going
to buy and for the cost of one bucket. Ask the user the color of
the paint. Calculate and return what he or she owes. Change the
color of the font to the color of the paint.
Use .innerHTML to display your output.
Extra Credit
1. Use the catch/try/throw statements to check for invalid input if
the user doesn’t give you a valid value for the number of buckets,
such as a number less than 0, or gives you no input, or types in a
string, and so on. <br />
2. Check that the user doesn’t give you a color of paint that is
the same color as the background of your document or you will not
be able to see the color of the font.
Please find the JS program for the above scenario
<!DOCTYPE html>
<html>
<head>
<title>Cost of Paint Buckets</title>
<script type="text/javascript">
function paintBucket() {
var message;
var n = document.getElementById("t1").value;
var c = document.getElementById("t2").value;
var red = document.getElementById("t3").value;
message = document.getElementById("result");
message.innerHTML = "";
try{
if(n > 0) document.getElementById("result").innerHTML =
"<br><br>The Cost of the buckets is " + n * c;
if(n < 0) throw "less than 0.";
if(n == " ") throw "Empty.";
if(typeof n == "string") throw "a String.";
}
catch(err) {
message.innerHTML = "<br><br>Bucket number is " +
err;
}
}
</script>
</head>
<body>
<input id="t1" placeholder="Enter number of
buckets"><br>
<input id="t2" placeholder="Enter cost of one
bucket"><br>
<input id="t3" placeholder="Enter color of
paint"><br><br>
<input type="button" onClick="paintBucket()" Value="Click me"
/>
<span id = "result"></span>
</body>
</html>
Explanation: By using three text fields, we take the user input. Using the function paintBucket(), input values are evaluated to find the cost. Here, exception handling is done using try,catch to handle input value of number of buckets for less than 0, empty or string. The output is printed respectively.
To add the color property to the code, the 'fontcolor()' function can be explored and implemented.
Hope this helps.
Please write back in case of more queries.
Write a function that returns the total cost of any number of buckets of paint. Ask...
Javascript: Write a function that returns the total cost of any number of buckets of paint. Ask the user how many buckets he or she is going to buy and for the cost of one bucket. Ask the user the color of the paint. Calculate and return what he or she owes. Change the color of the font to the color of the paint. Use .innerHTML to display your output. Check that the user doesn’t give you a color of...
I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...
I am required to use the try - catch block to validate the input as the test data uses a word "Thirty" and not numbers. The program needs to validate that input, throw an exception and then display the error message. If I don't use the try - catch method I end up with program crashing. My issue is that I can't get the try - catch portion to work. Can you please help? I have attached what I have...
Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...
I have the code buts its not working as this below instruction can anyone help Use the requirements from the pizza part of Assignment 6 and do the following using CSS and an internal style sheet: 1. Your Javascript function should be in an external file (don’t forget to move it up to studentweb too) 2. Put a red border of 300px in width around the form 3. There should be three Div sections: header, main_body, and footer. 4. Center the name of your...
Write a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock, for example 23:47:55). Here are the input errors (exceptions) that your program should detect and deal with: Receive the input from...
Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with: 4 for Visa cards 5 for MasterCard credit cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card...
build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...
12p
I need help this is Python
EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...
Problem: Create a program that will ask scientist in tracking the resistances of products from various batches. The resistances of good resistors should be between 3 and 3.5 inclusive. Your program will need to track the number of resistances that are too high (>3.5 ohms), the number of resistances that are too low (<3.0ohms) and calculate the average of the resistances that fall in the proper range (>=3 and <= 3.5). Your program should prompt the user to enter name...