Jump to content

Cane somebody help me


guyhautier

Recommended Posts

Hello,

Can somebody help me to write a javascript that drives two numbers asks the user. The two numbers compare with each other and allow javascript determine the number entered is greatest.

 

Thank you for helping.

 

Guy Hautier.

Edited by guyhautier
Link to comment
Share on other sites

<!DOCTYPE html><html><body><input type="text" id="first" value="0" /><input type="text" id="second" value="2" /><input type="button" onclick="check()" /><script>function check(){if( parseInt(document.getElementById('first').value) > parseInt(document.getElementById('second').value) ) alert('1>2');else alert('2>1');}</script></body></html>
Link to comment
Share on other sites

<!DOCTYPE html><html><head><meta charset="utf-8"><title>tab</title><script>window.onload = function(){ document.getElementById('btn1').onclick = check; }function check(){var a = Number(document.getElementById('a').value);var b = Number(document.getElementById('b').value);// Number() is very similar to parseFloat()var out1 = document.getElementById('out1');var out2 = document.getElementById('out2');var out3 = document.getElementById('out3');if(a<B) { out1.innerHTML = 'true'; }else{  out1.innerHTML = 'false'; } if(a>B) { out2.innerHTML = 'true'; }else{  out2.innerHTML = 'false'; } if(a==B) { out3.innerHTML = 'true'; }else{  out3.innerHTML = 'false'; } }</script></head><body>A:<input type="text" id="a" />   B:<input type="text" id="b" /><input type="button" value="Test" id="btn1" /><hr/>A<B ? <span id="out1"></span><br/>A>B ? <span id="out2"></span><br/>A=B ? <span id="out3"></span></body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...