Skip to main content

Posts

Showing posts from October, 2022

strings in javascript

 here in this blog we are going to learn about the strings in the javascript replit link(fb login) here are the following examples. let name ="anwar" // console.log(name) // console.log(name.length) // console.log(typeof name) // console.log(name[1]) // // template literals in StringList // let name1= "sabih" // let name2="anwar" // let sentence=`my name is ${name1} ${name2}` // console.log(sentence) // // escape sequence characters // name='anw\'ar' // console.log(name) // name='anw\nar' // console.log(name) // name='anw\tar' // console.log(name) // name='anw\rar' // console.log(name) // escape sequence character types // \b Backspace // \f Form Feed // \n New Line // \r Carriage Return // \t Horizontal Tabulator // \v Vertical Tabulator // console.log(name.toUpperCase()) // console.log(name.toLowerCase()) // console.log(name.slice(2)) // console.log(name.slice(2,4)) // console.log(name.replace("an...

function in javascript

 here in this blog we are going to study about function in javascript repel for functions(fb login) so here is the code as follows // function in javascript function oneplusavg(x,y) {   console.log("done")   return Math.round(1+(x+y)/2) } // modern function writing way // this is arrow function const hello = ()=>{   console.log("arey maza aa gaya bhai") } let a=1; let b=2; let c=3; hello(); console.log("one plus average of a and b is ", oneplusavg(a,b)) console.log("one plus average of b and c is ", oneplusavg(b,c)) console.log("one plus average of a and c is ", oneplusavg(a,c))

while and do while loop in javascript

 so in this blog we will learn about the while and do while loop of javascript replit link(login with fb) here are the codes as follows // while loop in javascript let n=prompt("enter the value of n") n=Number.parseInt(n) let i=0; // while (i<n){ //   console.log(i) //   i++; // } // do while loop in javascript do{   console.log(i)   i++; }while(i<n)

for loop, for in loop, for of loop in javascript

 here in this blog we are going to work with the  for loop for in loop  for of  loop link for replit(login from fb) so here are the following codes as follows //for loop in javascript for (let i=0;i<5;i++){console.log(i)} // program to add first natural numbers let sum=0 let n = prompt("enter the value of n") n= Number.parseInt(n) for(let i=0;i<n;i++)//here we are using let so the value is only valid inside the curly brackets only but when we work with var instead of let than it becomes global and outside also i value can be obtained {sum += (i+1)} console.log("the sum of "+ n + " natural numbers is" + sum ) //for in loop in javascript // let obj = { //   sabih:99, //   anwar:98, //   shayaan:100, //   ghufrana:23, //   rizwana:66 // } // for(let a in obj){console.log("marks of "+ a+" are "+obj[a])} // // for of loop in javascript it mainly works in arrays // for(let b of "shayaan"){console.log(b)}

if else statement in javascript and ternary operator

 here in this blog we are going to work with the if else and the ternary operator also link for this example link for example replit ka login facebook see karo let a =prompt("hey whats your age"); a= Number.parseInt(a); if (a<0){alert("this is an invalid age")} if (a<9){alert("you are a kid and dont even think of driving")} if (a<18 && a>=9){alert("you can think of driving after 18")} if (a>18){alert("you are eligible for driving")} //here we are working with the ternary operator which satisfies the condition at the same line console.log("you can",(a<18?"not drive":"drive"))