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




    4 comments:

    1. 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

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

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