HW4

In this example below you will see how to do a HW4 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by isaychris, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright isaychris ©
  • HTML
  • CSS
  • JavaScript
    <!DOCTYPE html>
<html lang="en">

<head>
  <title> HW4 </title>
  <meta charset="utf-8" />
  <link rel="stylesheet" type="text/css" href="styles.css">
  <script src="https://codepen.io/isaychris/pen/qPVEdL.js"></script>
</head>

<body>
  <h1>Fruit Shop</h1>
  <table>
    <caption> Sales Tax: 7.75% </caption>
    <tr>
      <th scope="col">Fruits</th>
      <th scope="col">Price</th>
      <th scope="col">Quantity</th>
    </tr>
    
    <tr>
      <td>🍎 Apple</td>
      <td>.59¢</td>
      <td><input type="number" id="apple" min="1" max="99">
      </td>
    </tr>

    <tr>
      <td>🍊 Orange</td>
      <td>.49¢</td>
      <td><input type="number" id="orange" onchange="validate(orange.value)">
      </td>
    </tr>
    <tr>
      <td>🍌 Banana</td>
      <td>.39¢</td>
      <td><input type="number" id="banana" onchange="validate(banana.value)">
      </td>
    </tr>
  </table>    
  <br>
  <input id="submit" type="submit" onclick="clicked()" value="Submit" />
</body>
</html>

/*Downloaded from https://www.codeseek.co/isaychris/hw4-qPVEdL */
    body {
  font-family: verdana;
}
th {
  color: #757575;
  background-color: #f5f5f5;
}
td, th {
  padding: 10px 30px 10px 30px;
}
table, td, th {
  border-collapse: collapse;
  border: 1px solid #e3e3e3;
  text-align: center;
}
table {
  width: 396px;
}
#apple, #orange, #banana, #total {
  width: 70px;
}
#submit {
  width: 396px;
  height: 30px;
}



/*Downloaded from https://www.codeseek.co/isaychris/hw4-qPVEdL */
    function clicked() {
  var a = document.getElementById("apple").value;
  var b = document.getElementById("orange").value;
  var c = document.getElementById("banana").value;

  total = a * 0.59 + b * 0.49 + c * 0.39;
  taxtotal = total * 1.0775;
  alert(
    "Thank you for shopping. Your total cost is $" + taxtotal.toFixed(2) + "."
  );
  return false;
}

function validate(num) {
  if (isNaN(num) || num < 1 || num > 99) {
    alert("[Error] Please enter a quantity value between 1-99.");
  }
  return false;
}


Comments