Question

In: Computer Science

•Make the title of the page " Nearest Integer”. This is a rounding application. •Assume you...

•Make the title of the page " Nearest Integer”. This is a rounding application.

•Assume you are given a number with values after the decimal point, such as 3.14. Is

3.14 nearest to 3 or 4? Your program should figure this out.

•You can get the lower integer of any positive floating-point value using “parseInt”. You

can get the higher integer by simply taking the lower value and adding 1.

•Determine which integer (higher or lower) is closer to your value and print that result.

•.Create these empty “div” element(s) on the screen: results

•Put one input text boxes on the screen and a button. Label the first box as “Enter the

first number.” Put a button on the screen with the text that reads “Determine the

nearest integer.”

•When the user enters a floating-point number and clicks the button, the “results” div

box should determine the nearest integer. “The nearest integer is 3.”

•To make this problem a little easier, assume that you will only be given a positive

number.

Solutions

Expert Solution

Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    body {
      margin: 0px 10px;
      font-family: Arial;
    }

    header {
      background-color: cornflowerblue;
      padding: 10px;
      color: aliceblue;
      text-align: center;
      font-size: 25px;
      font-weight: bold;
    }

    .input-area {
      width: 50%;
      margin: auto;
      padding: 20px;
    }

    input {
      padding: 8px;
      margin-bottom: 10px;
    }

    button {
      padding: 8px;
      background-color: cornflowerblue;
      color: aliceblue;
      border: 2px solid darkblue;
      border-radius: 4px;
      cursor: pointer;
    }

    .results {
      text-align: center;
      font-size: 30px;
      color: cornflowerblue;
    }
  </style>

  <title>Nearest Integer</title>
</head>
<body>
  <header>Nearest Integer</header>

  <div class="input-area">
    <label for="input">Enter the first number</label>
    <input type="text" id="input" required>
  
    <button onclick="getNearestInteger()">Determine the nearest integer</button>
  </div>

  <div class="results">

  </div>

  <script>
    function getNearestInteger() {
      // Get elements and their values
      var input = document.getElementById('input').value;
      var result = document.querySelector('.results');

      var integer = parseInt(input); // Getting lower value

      if ((input - integer) >= 0.5) {
        integer = integer + 1;
      }

      result.innerHTML = `<b>The nearest integer is ${integer}</b>`
    }
  </script>
</body>
</html>

Output:

Code Screenshot:


Related Solutions

What is the predicted performance time(rounding to the nearest 10th decimal) for administrator 1?
Admin Experience Complexity Performance 1 26 1 45 2 32 3 78 3 8 3 120 4 60 2 68 5 72 5 140 6 20 5 135 Question 1. What is the predicted performance time(rounding to the nearest 10th decimal) for administrator 1? Question 2. What is the predicted performance time(rounding to the nearest 10th decimal) for administrator 2? Question 3. What is the predicted performance time(rounding to the nearest 10th decimal) for administrator 3? Question 4. What is...
Prepare a 3-5 page paper (not including the title page and reference page) in which you...
Prepare a 3-5 page paper (not including the title page and reference page) in which you review the wellness and prevention services page of a local hospital’s website. Develop a paper in which you discuss how the wellness and prevention site is a marketing effort for the hospital. In your paper, identify and consider customers (patients, physicians, etc.) that are addressed in the site. How does the site offer value to these customers? The paper should be written in APA...
Prepare a 3-5 page paper (not including the title page and reference page) in which you...
Prepare a 3-5 page paper (not including the title page and reference page) in which you discuss the similarities and differences between public and private health insurers. How could these differences affect marketing strategies?
Can anyone fix this code? The code isn't rounding the answer to the nearest whole number...
Can anyone fix this code? The code isn't rounding the answer to the nearest whole number like 2.345 should be 2 and 2.546 should be 3 but the round() function isn't working as expected. The round() function is rounding 2.546 to 2 which is incorrect since 4 and below should be rounded to 2 and 5 and above should be rounded to 3. Here is the code: #importing xlwt library to write into xls import xlwt from xlwt import Workbook...
Create an empty Web Site application named Bakery. Add a new Web page named Default.aspx to the application. Change the DOCUMENT object's Title property to Meyer's.
In Visual BasicCreate an empty Web Site application named Bakery. Add a new Web page named Default.aspx to the application. Change the DOCUMENT object's Title property to Meyer's. The application should allow the user to enter two items: the number of doughnuts ordered and the number of muffins ordered. The application should should display the total number of items ordered and the total sales amount, inlcuding a 5% sales tax. A doughnut costs .50; a muffin costs .75. Save the...
1. All forecasts should be rounded to an integer number (regular rounding). Use Excel to do...
1. All forecasts should be rounded to an integer number (regular rounding). Use Excel to do your computations. Each part of the problem should be on a different Excel Sheet/Tab. Part (a)    Use the 6-period moving average method to forecast for these data and for the first six months of the third year. Compute MSD/E, MAD, MAPE, and Bias. Month (t) Model 3 A(t) 1 148 2 125 3 78 4 53 5 25 6 29 7 9 8...
Assignment #1: 3-Day Diet Record Required to Submit: Title Page 3-Day Diet Record Title page must...
Assignment #1: 3-Day Diet Record Required to Submit: Title Page 3-Day Diet Record Title page must include the following information, which must be centered vertically and horizontally on the first page: ∙ The title: Semester Diet Project ∙ Your Name ∙ Course Title and Section Number Completing the 3-Day Diet Record For this assignment, you will be completing a 3-day diet record, which will include two weekdays and one weekend day. In the Diet Project Resources Module in Canvas, you...
Write a 1-2-page paper (not including title page and reference page) that describes the following: Ø...
Write a 1-2-page paper (not including title page and reference page) that describes the following: Ø You are caring for a patient with c-diff as part of your workload assignment. Discuss what c-diff is and how it is transmitted (how you can get it)? Ø What actions will you take as a nurse to protect yourself and the other patients on the unit when taking care of your patient? You should include a minimum of 3 scholarly references (suggestion on...
Write a 1-2-page paper (not including title page and reference page) that describes the following: Ø...
Write a 1-2-page paper (not including title page and reference page) that describes the following: Ø You are caring for a patient with c-diff as part of your workload assignment. Discuss what c-diff is and how it is transmitted (how you can get it)? Ø What actions will you take as a nurse to protect yourself and the other patients on the unit when taking care of your patient? You should include a minimum of 3 scholarly references (suggestion on...
Write a 3-4 page (excluding title page an references page) paper applying a nursing philosophy to...
Write a 3-4 page (excluding title page an references page) paper applying a nursing philosophy to nursing practice. Explanation for grading the reflection paper follows: Grading Components Reflect on what is important to you as an individual and as a nursing student. Think about what you believe and what you value. Develop a paper that includes the following: Personal Values (4 points): Identify three values and beliefs that are important to you personally. Professional Values (4 points): Identify the values...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT