Data Types
datatypes.html
<!DOCTYPE html> <html> <head> <title>Data Types</title> <link rel="stylesheet" type="text/css" href="datatypes.css"> </head> <body> <input type="text" id="num1"><br> <input type="text" id="num2"><br> <input type="submit" onclick="multiply()" value="×"><br> <input type="button" onclick="divide()" value="÷"><br> <span id="answer"></span> <script src="datatypes.js"></script> </body> </html>
datatypes.css
body{ background-color: seashell; }
datatypes.js
var num1, num2, answer, feedback; function setValues(){ num1 = parseInt(document.getElementById("num1").value); num2 = parseInt(document.getElementById("num2").value); answer = 0; feedback = ""; } function giveAnswer(){ feedback = "The answer is: " + answer.toString(); document.getElementById("answer").innerHTML = feedback; } function multiply(){ setValues(); answer = num1 * num2; giveAnswer(); } function divide(){ setValues(); answer = num1 / num2; giveAnswer(); }
- add a plus and minus button
- what does
parseInt
andtoString()
do? What data types would i use these methods with, and what would be the resulting data types? - What is string concatenation? Where does this happen in this code?
- What is the difference between float and integer?