comparison

by lakshmipriya001

HTML

<h1>Compare Two Numbers</h1>

<div id="inputs">
  <input id="a" value="8">
  <span id="comparison"></span>
  <input id="b" value="4">
</div>
<button id="submit">Compare</button>

CSS

body, input, button {
  font-family: sans-serif;
  font-size: 20px;
  text-align: center;
}
#inputs {
  margin-bottom: 30px;
}
input {
  width: 50px;
  padding: 10px;
}
button {
  background: #CCC;
  border: 1px solid rgba(0,0,0,.2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 1px 2px rgba(0,0,0,.25);
  border-radius: 5px;
  padding: 10px 20px;
}
button:hover {
  background: #DDD;
}
button:active {
  background: #BBB;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.25);
}
#comparison {
  display: inline-block;
  width: 40px;
}

JavaScript

// When the user clicks the button, run the compare function
document.getElementById('submit').onclick = compare;

function compare() {
  
  // Get the value stored in #a
  var a = document.getElementById('a').value;
  a = parseFloat(a);
  
  // Get the value stored in #b
  var b = document.getElementById('b').value;
  b = parseFloat(b);
  
  // Set up a variable to store the comparison operator
  var comparison;
  
  // TODO: Set `comparison` string based on relationship between a and b
  if(a > b) {
    comparison = '>';
  } else if(a < b) {
    comparison = '<';
  } else {
    comparison = '=';
  }
  
  // Print `comparison` string on the page
  document.getElementById('comparison').innerHTML = comparison;
  
}