Skip to content

Instantly share code, notes, and snippets.

@cmjaimet
Last active February 19, 2019 16:03
Show Gist options
  • Save cmjaimet/6cabaf09fe695aa899bf4b34420583f6 to your computer and use it in GitHub Desktop.
Save cmjaimet/6cabaf09fe695aa899bf4b34420583f6 to your computer and use it in GitHub Desktop.
Even/Odd JS
<div id="numbr"></div>
<div id="evenodd"></div>
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