Skip to main content

Posts

Showing posts with the label JavaScript Code

Javascript division by 0

# Javascript Divide by Zero Check In JavaScript, division by zero does not cause an any error. While, it generates Infinity, which is a reserved word in JavaScript. Let's try to create simple example: If the division number is positive then it generates positive Infinity . Example 1 : divided by zero; In this code, we will divide the positive integers by 0. < script type = "text/javascript" > var a = 10 , b = 0 ; var division ;   di...

Properties list in JavaScript

In javascript, there are many ways to create objects such as an array, object method, a new keyword, object literal, and more. # Program to create a list of fruits properties In this section, we will use an object literal method to create the properties lists and also iterate properties by using a fo-in loop. Let's see, the simple instance:   ➤ Example 1: program for creating a list of fruits; In this code, we used the "object literal" method to create a list of object properties. < script type = "text/javascript" > var fruits = { ...

Print table using javascript

Program to print table In this section, you will learn how you can easily print table like : "5", "10", "12", "25", "100" and more. In this example, we print table of 5 using javascript. Let's try to create a simple program :   ➤ Code : JavaScript program to print table for a given number; <script> //Enter your number here, as often as you want to print table. var number = 5; for(let i = 1; i<=10; i++) { let table = number * i; console.log(number+"*"+i+"= "+table); } <script> Output :

Create diamond shape program in Javascript

Program to print Diamond shape In this section, you will learn how you can easily print 'diamond shape' and 'pyramid shape' using javascript Diamond shape program Let's see, the simple program to create a diamond shape:   ➤ Code : Diamond shape program in javascript; <script> function diamond(val){ var y, w, shape = ''; for(y = 0; y < val * 2 - 1; y++) { w = y < val ? y : val * 2 - y - 2; shape += Array(val - w).join(' ') + Array(w + 1).join('* ') + '*\n'; } document.write('<pre>' + shape + '</pre>'); // console.log(shape); } //Enter your number here, as often as you want to size of diamond. diamond(5); <script> Output : * * * * * * * * * * * * *...

Program to display Hello World one hundred times using javascript

Program to display Hello World In this section, you will learn how you can easily display or print 'Hello World' message one or more then ones times in javascript. In this example, we print 100 times. Let's try to create a simple program :   ➤ Code : hello-world program; <script> //Enter your number here, as often as you want to print. let times = 100; for(let i = 1; i<=times; i++) { console.log(i+". Hello word!"); } <script>

How to get text from p tag in javascript | Get paragraph text using js.

Get paragraph text using JavaScript The getElementById() method is used to return the element that has the ID attribute with the specified value. This is one of the most common methods in the HTML DOM and It is used almost every time we want to manipulate an element on our document. This method returns a null value, if no elements with the specified ID exists. Note : The ID should be unique within a page. However, if more than one element with the specified ID exists, it returns the last element in the javascript code, Let's see. Let's see the simple instance :   ➤ Example : <p id="element">www.coderwebsite.com</p> <script> var get_text = document.getElementById("element").innerHTML; document.write(get_text); </script> Output : www.coderwebsite.com

How to overwrite text in p tag using JavaScript ?

Javascript find and replace text in html In this post, we will learn how to change/overwrite the contents of the p tag using JavaScript, with the help of class name and id, and other. Let's see # Method 1 : Change inner txt by using id :   ➤ Example : <p id="p-tag">www.coderwebsite.com</p> <script> document.getElementById('p-tag').innerText = "Change Me!" </script> # Method 2 : Change inner txt by using a class name:   ➤ Example : <p class="p-tag">www.coderwebsite.com</p> <script> x=document.getElementsByClassName('p-tag'); // Find the elements for(var i = 0; i < x.length; i++){ x[i].innerText="Hello JavaScript!"; // Change the content } </script> # Method 3 : Change inner txt on onclick button using a class name:   ➤ E...

How to remove the date and .html from every blogger post url

#Remove date and .html from blogger post url A Common search term which every blogger search is How to Remove Date From Blogger Post URL or how do I remove date from blogger permalink? Follow the steps below and then date and .html will be removed from the URL of your blogger post. Step 1 : Login to your Blogger blog and select Theme / Template. Step 2 : Click on Edit HTML and paste the below code just above the </head> tag let's see code :   ➤ Code : mycode.js; Copy code <script type='text/javascript' > //<![CDATA[ // BloggerJS v0.3.1 var urlTotal,nextPageToken,postsDatePrefix=!1,accessOnly=!1,useApiV3=!1,apiKey="",blogId="",postsOrPages=["pages","posts"],jsonIndex=1,secondRequest=!0,feedPriority=0,amp="&"[0];function urlVal(){var e=window.location.pathname,t=e.length;return...