Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript one input field connect to several functions
    primarykey
    data
    text
    <p>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:</p> <ol> <li>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...)</li> <li>check if the year is leap year (true/false or yes/no, ...)</li> <li>calculate the sum of the numbers i ask (2018 = 11, 2013=6, ...)</li> <li>if the number is Prime number (true/false, yes/no, ...)</li> <li>reverse number (2013 = 3102, 2018=8102, ...)</li> <li>show the chinese zodiac sign for year</li> <li>convert year to roman numerals (1=I, 2=II, 10=X, ...)</li> </ol> <p>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.</p> <p>Examples i find on internet:</p> <pre><code>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"; } } </code></pre> <p>reverse:</p> <pre><code>&lt;script type="text/javascript"&gt; var year, b = 0; year= parseInt(prompt("Enter year: ")); document.write("You've entered: " + year+ "&lt;br /&gt;"); while(year&gt; 0) { b = b * 10 b = b + parseInt(year% 10) year= parseInt(year/ 10) } document.write("Reverse numbers: ", b); &lt;/script&gt; </code></pre> <p>sum numbers:</p> <pre><code>&lt;script&gt; function find() { var sum = 0; var no = parseInt(frm.txt1.value); while (no &gt; 0) { sum = sum + no % 10; no = Math.floor(no / 10); } alert("Sum of digits " + sum); } &lt;/script&gt; &lt;form name="frm"&gt; Enter a Number:&lt;input name="txt1" type="text" /&gt; &lt;input name="b1" onClick="find();" type="button" value="display" /&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload