I'm very new to programming and have some problems. I'would like to create one form (in html and javascript), where I can do some calculations. This is about numbers and years. So at first I need to put input field, where I can type year (like 2013). This input value will be connected to several functions:
- calculating difference from current year (if I ask for 2018 it should write 5, or if I ask for 2000 iz shoul write -13 and so on...)
- check if the year is leap year (true/false or yes/no, ...)
- calculate the sum of the numbers i ask (2018 = 11, 2013=6, ...)
- if the number is Prime number (true/false, yes/no, ...)
- reverse number (2013 = 3102, 2018=8102, ...)
- show the chinese zodiac sign for year
- convert year to roman numerals (1=I, 2=II, 10=X, ...)
I did find some function, but i just can't put this together that will work. I would be very helpful if someone can help with this.
Examples i find on internet:
function isleap() {
var yr = document.getElementById("year").value;
if ((parseInt(yr) % 4) == 0) {
if (parseInt(yr) % 100 == 0) {
if (parseInt(yr) % 400 != 0) {
alert("Not Leap");
return "false";
}
if (parseInt(yr) % 400 == 0) {
alert("Leap");
return "true";
}
}
if (parseInt(yr) % 100 != 0) {
alert("Leap");
return "true";
}
}
if ((parseInt(yr) % 4) != 0) {
alert("Not Leap");
return "false";
}
}
reverse:
<script type="text/javascript">
var year, b = 0;
year= parseInt(prompt("Enter year: "));
document.write("You've entered: " + year+ "<br />");
while(year> 0) {
b = b * 10
b = b + parseInt(year% 10)
year= parseInt(year/ 10)
}
document.write("Reverse numbers: ", b);
</script>
sum numbers:
<script>
function find() {
var sum = 0;
var no = parseInt(frm.txt1.value);
while (no > 0) {
sum = sum + no % 10;
no = Math.floor(no / 10);
}
alert("Sum of digits " + sum);
}
</script>
<form name="frm">
Enter a Number:<input name="txt1" type="text" />
<input name="b1" onClick="find();" type="button" value="display" />
</form>