Recent

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



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:


Display current day and time

Code

<script type="text/javascript">
var d = new Date();

document.write("Today is: "+d);

document.write("<br>Year is "+(d.getFullYear()));
document.write("<br>Month is "+(d.getMonth()+1));
document.write("<br>Day is "+(d.getDate()));
document.write("<br>Day of Week is "+(d.getDay()+1));
</script>

Output




    13 comments:

    1. Enormous blog you individuals have made there, I entirely appreciate the work.
      her latest blog

      ReplyDelete
    2. 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. 金融作业代写

      ReplyDelete
    3. Interesting 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

      ReplyDelete
    4. Merci 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 ».
      Je viens de lire votre commentaire écrit il y a déjà quelques années.

      Au plaisir !

      dede101

      ReplyDelete
    5. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks Java Tutorial

      ReplyDelete
    6. They are able to make changes and edits on the fly, without much notice upfront from the client.
      brand agencies San Francisco

      ReplyDelete
    7. Their talent and intelligence, coupled with their enthusiasm, made for a seamless partnership.
      top UI design companies

      ReplyDelete
    8. Each time I used to always check blog posts within the first hours in the break of day, because I like to get information increasingly more.
      top design agencies

      ReplyDelete
    9. 留学生网课代上代考,作业论文代写,海外课程辅导平台 -你的作业代写专家assignment-daixie.com
      留学生网课代上代考,作业论文代写,海外课程辅导平台 -你的作业代写专家assignment-daixie

      ReplyDelete
    10. Accessing free JavaScript examples with code is a fantastic way to learn and enhance web development skills. These real-world snippets demonstrate concepts like DOM manipulation, form validation, and interactive features. How Play Games Exploring such examples aids programmers in grasping JavaScript's power and versatility.

      ReplyDelete