Posts

Showing posts from January, 2021

JavaScript While Loop

Image
  The While Loop The while loop loops through a block of code as long as a specified condition is true. Syntax while ( condition ) { // code block to be executed } < !DOCTYPE html > < html > < p id ="demo" > JavaScript While Loop < /p > < script > var txt = "" ; var i=0; while (i < 10 ) {   text += "The number is " + i;   i++; } document.getElementById( "demo" ).innerHTML = text; < /script >     < /body > < /html >     The Do/While Loop The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. Syntax do { // code block to be executed } while ( condition ); < !DOCTYPE html > < html > < p id ="demo" > JavaScript Do/While Loop < /p > < script > var txt = &qu

JavaScript For Loop

Image
  JavaScript Loops Loops are handy, if you want to run the same code over and over again, each time with a different value. Often this is the case when working with arrays: text += cars[ 0 ] + "<br>" ; text += cars[ 1 ] + "<br>" ; text += cars[ 2 ] + "<br>" ; text += cars[ 3 ] + "<br>" ; text += cars[ 4 ] + "<br>" ; text += cars[ 5 ] + "<br>" ; < !DOCTYPE html > < html > < p id ="demo" > JavaScript can change HTML content. < /p > < script >  var cars = [ "BMW" , "Volvo" , "Saab" , "Ford" , "Fiat" , "Audi" ]; var text = "" ; var i; for (i = 0 ; i < cars. length ; i++) {   text += cars[i] + "<br>" ; }  document. getElementById ( "demo" ). innerHTML = text;   < /script >     < /body > < /html >  

JavaScript

Image
  What is JavaScript and Why it is Used? JavaScript is a programming language . Used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are language that give structure and style to web pages,JavaScript gives web pages ,JavaScript gives web pages interactive elements that engage a user. J avaScript can change HTML content one of many JavaScript HTML methods is getElenentById( ). the example below “finds” an HTML elements(with id=”demo” and change the elements content (innerHTML) to “Hello JavaScript”.   < !DOCTYPE html > < html > < p id ="demo" > JavaScript can change HTML content. < /p > < button type ="button" onclick ="document.getElementById("demo"),innerHTML="Hello Javascript!" > Click me < /button > < /body > < /html >   The < script > tag