Question

<!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money...

<!DOCTYPE html>

<html>

<body>

<script>

//

// Write a function that calculates the amount of money a person would earn over

// a period of years if his or her salary is one penny the first day, two pennies

// the second day, and continues to double each day. The program should ask the

// user for the number of years and call the function which will return the total

// money earned in dollars and cents, not pennies. Assume there are 365 days

// in a year.

//

function totalEarned(years) {

/////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the next comment block. Do not alter //

// any code in any other part of this file. //

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the previous comment block. Do not alter //

// any code in any other part of this file. //

/////////////////////////////////////////////////////////////////////////////////

}

var years = parseInt(prompt('How many years will you work for pennies a day? '));

var totalDollarsEarned = totalEarned(years);

alert('Over a total of ' + years + ', you will have earned $' + totalDollarsEarned);

</script>

</body>

</html>

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

ANSWER:

CODE:

<!DOCTYPE html>

<html>

<body>

<script>

function totalEarned(years) {
var amount=0

// converting years into days
var days=years*365;

// looping each day
for(i=0;i<days;i++){

// As the amount doubles we will write it as exponential of 2 and add it to total amount
amount += 2**(i);        
}

// converting pennies to dollars
amount = amount/100;        


return amount
}

var years = parseInt(prompt('How many years will you work for pennies a day? '));

var totalDollarsEarned = totalEarned(years);

alert('Over a total of ' + years + ', you will have earned $' + totalDollarsEarned);

</script>

</body>

</html>

RESULTS:

How many years will you work for pennies a day? 11 OK Cancel Activate Windows Go to Settings to activate Windows.

Over a total of 1, you will have earned $7.515336264876266e+107 Prevent this page from creating additional dialogs | OK Activ

NOTE:

As you can see from the results.

The Question might not be accurate as doubling the amount each day we result in an amount of

5764607523034235$ - on the last day of 2nd month(60th day) itself.

And if we continue so on the amount will be so large that it is not possible for the browser to display and it shows infinity.

SUGGESTION:

We can consider numbers days as input instead of years from the user. It would greatly decrease the shear size of the output and also might be more useful than the original question.

The output in this case after 5days is as follows.

How many years will you work for pennies a day? 51 Prevent this page from creating additional dialogs OK Cancel Activate Wind

Over a total of 5, you will have earned $0.31 Prevent this page from creating additional dialogs OK Activate Windows Go to Se

Add a comment
Know the answer?
Add Answer to:
<!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money...
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
  • <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- -->...

    <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // Write a program that asks the user to enter the amount that he or she has // budgeted for a month. Call a function that uses a loop that prompts the user // to enter each of his or her expenses for the month and keep a running total. // The loop finishes when the user...

  • <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- -->...

    <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // Write a program that prompts the user to enter a number within the range of // 1 through 10 and calls a function to display the roman numeral version of // that number. If the number is outside the range of 1 through 10, the program // should display an error message. // // The following...

  • I need Notebook++ coding! Thanks so much I will upvote! <!DOCTYPE html> <html> <body> <!-- replace...

    I need Notebook++ coding! Thanks so much I will upvote! <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!-->    <!-- -->    <!-- -->    <title> Jason Kidwell</title> <script> // // Scientists measure an object’s mass in kilograms and its weight in newtons. // If you know the amount of mass of an object in kilograms, you can calculate // its weight in newtons with the following formula: // //       weight=mass×9.8 // // Write a...

  • Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script>...

    Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script> function wrangleArray() { var string1 = prompt("Enter: This class is going to fast");//Must be entered by the user var string1 = "";//Is this right? I want that string to change later by a series of prompt questions document.getElementById("div1").innerHTML = "<p>" + sentence + "</p>"; var words = sentence.split(" ");//I need to convert my string to an Array is this the way to do it?...

  • <!DOCTYPE HTML> <html lang="en">    <title>JavaScript Array Lab</title>    <script src="script.js"></script>    <body>        <p>To...

    <!DOCTYPE HTML> <html lang="en">    <title>JavaScript Array Lab</title>    <script src="script.js"></script>    <body>        <p>To test your function, call divideArray() from the JavaScript console in the browser.</p>    </body> </html> Don't edit your code on the above code and do not copy from others', plz! // Put your solution here in script.js Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for...

  • How can I connect the html forms to php --> mysql database <!DOCTYPE html> <html lang="en">...

    How can I connect the html forms to php --> mysql database <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2> <center> Average: </h2> <h3> <center> Rate the following: </h2> <h3> <center> Rating Criteria: <br> Developing (0-5), Competent (6-10), Accomplished (10-15); </h3> <center> Judge Name: <input type="text" id="judge"> <br> <br> <center> 1. Articulate requirements and design of the project: <input type="text" id="num1"> <br> <br> 2. Plan the solution and implement the project: <input type="text" id="num2"> <br> <br> 3....

  • HTML only Design and implement a program that calculates the amount of money a person would...

    HTML only Design and implement a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should:ask the user for the number of daysdisplay a table showing what the salary was for each daythen show the total pay at the end of the period.The output should be displayed in the...

  • in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript...

    in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 5 Hands-on Project 5-2 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hands-on Project 5-2</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 5-2 </h1> </header> <article> <h2>Change of address form</h2> <form> <fieldset id="contactinfo"> <label for="addrinput"> Street Address </label> <input type="text" id="addrinput" name="Address" /> <label for="cityinput"> City </label> <input type="text" id="cityinput" name="City"...

  • <!DOCTYPE html> <html> <body> <h1>The onclick Event</h1> <p>The onclick event is used to trigger a function...

    <!DOCTYPE html> <html> <body> <h1>The onclick Event</h1> <p>The onclick event is used to trigger a function when an element is clicked on.</p> <p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html> in this code when I press chick me button the show me hello world, I need show hello world in another page how...

  • Write a program using Python that calculates the amount of money a person would earn over...

    Write a program using Python that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, then show the total pay at the end of the period. The output should be displayed...

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