Skip to content

Instantly share code, notes, and snippets.

@kyleturman
Created March 9, 2017 05:04
Show Gist options
  • Save kyleturman/94ceafe373671d9554f1633092adb7a7 to your computer and use it in GitHub Desktop.
Save kyleturman/94ceafe373671d9554f1633092adb7a7 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=94ceafe373671d9554f1633092adb7a7
<!DOCTYPE html>
<html>
<head>
<title>Number types</title>
</head>
<body>
<h1>Enter a number and I'll tell you what it is!</h1>
<input id="number" placeholder="Enter a number" />
<button id="number-button">Check number</button>
</body>
</html>
{"enabledLibraries":["jquery"]}
function checkNumber(number_string){
// Check the console to see what type
// this variable is!
console.log(number_string + " is a " + typeof(number_string));
// The `parseInt` function turns the
// string into a number
var number = parseInt(number_string);
// Check the console to see what type
// of variable this is!
console.log(number + " is a " + typeof(number));
if (number === 1) {
alert('This number is one!');
}
if (number === 2) {
alert('This number is two!');
}
// START HERE
// Finish the if statements and go all the way to 10!
// ...
}
$(document).ready(function() {
$("#number-button").on("click", function(){
var string_value = $('#number').val();
checkNumber(string_value);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment