Last active
February 19, 2019 16:03
-
-
Save cmjaimet/6cabaf09fe695aa899bf4b34420583f6 to your computer and use it in GitHub Desktop.
Even/Odd JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="numbr"></div> | |
<div id="evenodd"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_even( num ) { | |
return new Promise( function( resolve, reject ) { | |
if ( 0 === num % 2 ) { | |
resolve( num ); | |
} else { | |
reject( num ); | |
} | |
} ); | |
} | |
function rand_number( min, max ) { | |
return Math.round( min + Math.random() * ( max - min ) ); | |
} | |
let numbr = rand_number( 10, 12 ); | |
document.getElementById('numbr').innerText = numbr; | |
is_even( numbr ).then( | |
function( response ) { | |
document.getElementById('evenodd').innerText = "Success! " + response + " is even, Steven"; | |
}, | |
function( error ) { | |
document.getElementById('evenodd').innerText = "Failed! " + error + " is an Oddball"; | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment