Java Script Examples step by step with Codes
Four Examples of Java Script with codes
Calculate how many chocolates will you eat in you remaining life
Code
<form name="myform"> <input type="date" name="dob"/><label>Enter Your Date of Birth</label><br> <input type="number" name="num" placeholder="Enter Number of Choclates you eat per month"> <label>Enter How Many Choclates you eat in one month</label><br> <input type="button" value="Calculate" onclick="calc()"/> </form> <div>Total Number of choclates you will eat in your life is: <b><span id="result"></span></b><br><sub>* You have maximum age of 80 years</sub></div> <script type="text/javascript"> function calc() { var dob = document.forms['myform']['dob'].value; var num = document.forms['myform']['num'].value; var a =new Date(dob); var b = new Date(); var dayr = 29200 - ((((b.getTime()- a.getTime())/1000)/60)/60)/24; document.getElementById('result').innerHTML = (num/30)*dayr; } </script>
Output
Total Number of choclates you will eat in your life is:
* You have maximum age of 80 years
* You have maximum age of 80 years
Remove Char at given index
Code
<form name="myform"> <input type="text" name="mystr" placeholder="Enter a String"/> <input type="number" name="indx" placeholder="Enter Index of Character"> <input type="button" value="Create New String" onclick="nwstr()"/> </form> <div>New String is: <b><span id="result"></span></b></div> <script type="text/javascript"> function nwstr() { var mstr = document.forms['myform']['mystr'].value; var indx = document.forms['myform']['indx'].value; var newstr = mstr.substring(0,indx) + mstr.substring((Number(indx)+1)); document.getElementById('result').innerHTML = newstr; } </script>
Output
New String is:
Add word Py in start of the given string
Code
<form name="myform"> <input type="text" name="mystr" placeholder="Enter a String"/> <input type="button" value="Create New String" onclick="nwstr()"/> </form> <div>New String is: <b><span id="result"></span></b></div> <script type="text/javascript"> function nwstr() { var mstr = document.forms['myform']['mystr'].value; var newstr = "Py"+mstr; document.getElementById('result').innerHTML = newstr; } </script>
Output
New String is:
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai
ReplyDeleteEnormous blog you individuals have made there, I entirely appreciate the work.
ReplyDeleteher latest blog
I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. 金融作业代写
ReplyDeleteInteresting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon. buy real instagram likes gradual delivery
ReplyDeleted
ReplyDeleteMerci pour votre lien sur votre blog... j'étais intéressé au scripts Java lorsque j'étais dans la cinquantaine, je construisais des sites Internet alors... plus maintenant je me limite sur des plateformes comme « blogspot ».
ReplyDeleteJe viens de lire votre commentaire écrit il y a déjà quelques années.
Au plaisir !
dede101