JavaScript Tutorial

JavaScript For Loop 0

JavaScript For Loop

Program 1 “use strict” const ps=require(“prompt-sync”) const prompt=ps({sigint:true}) /* Program using for loop */ /* for(initialization;condition;increment/decrement) { } i=2 1 2 3 4 5 10 */ // let i,n // n=parseInt(prompt(“Enter the limit”)) //...

JavaScript Project – Guess the Number Game 0

JavaScript Project – Guess the Number Game

Program 1 <html> <head><title>Guess the Number Game </title> <script type=”text/javascript”> const compchoice=Math.floor(Math.random()*100)+1 let count=5 let i=0 function guess_number() { let userchoice userchoice=document.getElementById(“txtuser”).value i++ count– // alert(“User Choice: ” +userchoice) // alert(“computer Choice: ” +compchoice)...

JavaScript Project – Guess Random Number Game Console Version 0

JavaScript Project – Guess Random Number Game Console Version

Program 1 //Guess Random Number Game(Console Application) “use strict” const ps=require(“prompt-sync”) const prompt=ps({sigint:true}) let compchoice,userchoice let choice do { compchoice=Math.floor(Math.random()*100) console.log(“———–Guess Random Number Game————-“) console.log(“You have to guess a number(0-99) if you guess in...

JavaScript Project – Coin Toss Game Web Version 0

JavaScript Project – Coin Toss Game Web Version

Program 1 <html> <head><title>Coin Toss Game </title> <script type=”text/javascript”> function coin_toss_game() { let userchoice,compchoice compchoice=Math.floor(Math.random()*2) // alert(compchoice) userchoice=parseInt(document.getElementById(“txtuser”).value) if(userchoice==1 || userchoice==2) { if(compchoice==1) document.writeln(“<font color=green size=7>Its a Head….!</font>”) else document.writeln(“<font color=red size=7>Its a Tail….!</font>”)...

JavaScript Project – Coin Toss Game Console Version 0

JavaScript Project – Coin Toss Game Console Version

Program 1 // Coin Toss Game (Console Application) “use strict” const ps=require(“prompt-sync”) const prompt=ps({sigint:true}) //console.log(Math.random()) let choice let compchoice,userchoice do { compchoice=Math.floor(Math.random() * 2) console.log(“———-Coin Toss Game————“) console.log(“\t \t 1. Head \n\t\t 2. Tail”)...

JavaScript Geolocation API 0

JavaScript Geolocation API

Program 1 <html> <body> <center> <h1>JavaScript Code to find location </h1> <br> <font color=”blue” size=”5″>Click the button to show your coordinates.</font> <br> <button onclick=”showLocation()”>Click here to get location</button> <h1 id=”showresult”></h1> <script> const x =...

JavaScript Object Reference 0

JavaScript Object Reference

Program 1 class Test { constructor() { console.log(“Constructor …….”) this.a=10 } inrcrement() { ++this.a } } T1=new Test() // define T2=T1 // Reference T1.inrcrement() T1.inrcrement() console.log(T2.a) // T1=new Test() // define object // T2=new...

Types of for Loop in JavaScript 0

Types of for Loop in JavaScript

Program 1 “use strict” const ps=require(“prompt-sync”) const prompt=ps({sigint:true}) // Typs of For loop in Java Script /* for for in for of for each */ // let mydata=[10,20,30,40,50,60,70,80,90,100] mydata.forEach(element => { console.log(element) }); //...

“use strict” in JavaScript 0

“use strict” in JavaScript

Program 1 “use strict” const ps=require(“prompt-sync”) const prompt=ps({sigint:true}) a=100 console.log(a) var a=parseInt(prompt(“Enter a number”)) // a=100 // console.log(a) // a=”Hello” // console.log(a) // a=true // console.log(a)