Fred.
Well-known member
Hi,
I just started learing JS, I need to read 2 text fields and divide the largest nr. by the smallest and it may not be possible to divide by 0 (Has to show a alert) But negative numbers are allowed.
I think I started ok to make the objects and integers but I don't know how I have to divide and how I have to set all the parameters and else if...
Don't just post the solution please, try to explain me in a simple way what and how I have to do it. I'm trying to learn.
Thank you in advance.
This is the code I already have
	
	
	
		
				
			I just started learing JS, I need to read 2 text fields and divide the largest nr. by the smallest and it may not be possible to divide by 0 (Has to show a alert) But negative numbers are allowed.
I think I started ok to make the objects and integers but I don't know how I have to divide and how I have to set all the parameters and else if...
Don't just post the solution please, try to explain me in a simple way what and how I have to do it. I'm trying to learn.
Thank you in advance.

This is the code I already have
		Code:
	
	<script>
// make objects
    var eGetal1 = document.getElementById('getal1');
    var eGetal2 = document.getElementById('getal2');
 
// make integers
    var nGetal1 = parseInt(eGetal1.value);
    var nGetal2 = parseInt(eGetal2.value);
// divide
    var nTotaal = "";
    if( nGetal1 > nGetal2 ) {
     What goes here???;
}
    if( nGetal2 > nGetal1 ) {
    What goes here???;
}
// alert not possible to divide by 0
var eKnop = document.getElementById('deKnop');
eKnop.onclick = sendAlert;
 
function sendAlert(){
     alert('inpossible to divide by 0');
}
//output
var eOutput = document.querySelector('#output');
eOutput.innerHTML = nTotaal;
console.log('getal1: ' + nGetal1);
console.log('getal2: ' + nGetal2);
console.log('totaal: ' + nTotaal);
</script>
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
 
		

 (PS : I was never good at math)
 (PS : I was never good at math) 