Posts

Showing posts from February, 2024

Switch case make weekly to do list

var day = "abc" switch (day) {   case "Monday":     console.log("today is monday and go to office" );     break;   case "Tuesday":      console.log("today is Tuesday and go to mandir" );     break;   case "wednesday":      console.log("today is Wednesday and go to meeting");     break;   case "Thursday":      console.log("today is Thursday and go to sai baba mandir");     break;   case "friday":      console.log("today is Friday and last day of office" );     break;   case "saturday":      console.log("today is Saturday and go rest" );     break;   case "sunday":      console.log("today is sunday and go to movie" );     break;     default:console.log("no cond match") }

string practice test

 how to find the length of string let a = "navjotsingh" let b = a.length console.log(`the length of ${a} is ${b}`) =========================================================================== let a = "navjotsingh" let b = a.length console.log(a[2]) ========================================================================= string method

how to find the number is positive, negative and zero with if else statment

 var numb = -1; if (numb ===0){   console.log("zero") } else if(numb > 0){   console.log("positive") } else{   console.log("negative") }

for loop basic practice test for beeginer

1. Print numbers from 1 to 10: for (let i = 1; i <= 10; i++) {   console.log(i); }   2. Print even numbers from 2 to 20: for (let i = 2; i <= 20; i += 2) { console.log(i); } 3. Calculate the sum of numbers from 1 to 100: let sum = 0; for (let i = 1; i <= 100; i++) { sum += i; } console.log("The sum is:", sum); ------------------ 4. Print the multiplication table of 7: for (let i = 1; i <= 12; i++) { console.log(7 * i); } 5. Check if a number is even or odd: let number = 15; if (number % 2 === 0) { console.log(number + " is even."); } else { console.log(number + " is odd."); } 6. Print a pattern of stars: for (let i = 1; i <= 5; i++) { let stars = ""; for (let j = 1; j <= i; j++) { stars += "*"; } console.log(stars); } 7. Find the factorial of a number: function factorial(number) { let result = 1; for (let i = 1; i <= number; i++) { result *= i; } return result; } console.log(...

for loops js practice sum , factorial

Sum of all number  let sum = 0; let n = 3; for(let i = 0; i < n; i++){   sum += (i+1) } console.log(`the sum of first ${n} natural number is ${sum}`) ----------------------------------------------------------------------------------------------------------------- let num = 5; let factorial = 1; for(let i = 1; i <= num; i++){   factorial *=i; } console.log(`the factorial of {num} is : ${factorial}`) ---------------------------------------------------------------------------------------------------------------------

JavaScript: Check whether a given positive number is a multiple of 3 or a multiple of 7

  // JavaScript: Check whether a given positive number is a multiple of 3 or a multiple of 7 let a = Number ( prompt ( "enter the value" )) // let b = Number(prompt("enter the value")) if ( a % 3 == 0 || a % 7 == 0 ){     console . log ( `yes ${ a } is dividible ` ) } else {     console . log ( `no ${ a } is not devided ` ) }

JavaScript: Compute the sum of the two given integers

 let x = 5; let y = 6; function sun(x,y) {   if (x == y) {     return 3 * (x + y);   }    else {     return x + y;   } } console.log(sun(5, 12)); console.log(sun(5, 6));

Write a JavaScript program to calculate multiplication and division of two numbers (input from the user).

  var a = Number ( prompt ( "enter the number" )) var b = Number ( prompt ( "enter the number" )) console . log ( a + b ) console . log ( a * b )

Write a JavaScript program where the program takes a random integer between 1 and 10, and the user is then prompted to input a guess number. The program displays a message "Good Work" if the input matches the guess number otherwise "Not matched".

  var a = Number ( prompt ( "enter the value" )) if ( a < 10 ){     console . log ( "good work" ) } else {     console . log ( "Not match" ) }

find the area of a triangle where three sides are 5, 6, 7.

 var a = 5; var b = 6; var c = 7; var s = (a+b+c)/2; var area = Math.sqrt(s*(s-a)*(s-b)*(s-c)); console.log(area)

if else number is / by 2 and 3

  let a = 156;      if(a%2==0 || a%3==0){     console.log("number is divisible by 2 and 3")   }      else{     console.log("number is not divisible by 2 and 3")   }

logical operator practice

Image
  let a = 15; if(a<10 && a>20){   console.log("your age is between 10 and 20") } else{   console.log("your age is not between 10 and 20") }

ternary operator

 // var a = 100; // var b; // (a==b)?b = "true" : b = "false"; // console.log(b) var a = 10; console.log("you can", (a<18)? "not drive" : "drive");

switch case grade and age

 const grade = 'a'; switch (grade) {   case "a":     console.log("very good")     break;        case "b":     console.log("good");     break;        case "c":     case "c":       console.log("need improvement");     break     case "d":       console.log("not good");     break     case "e":       console.log("fail");     break   default:     console.log("this not valid grade") } --------------------------------------------------------------------------------- let a = 102; switch (a){   case 12:     console.log("your age is 12")     break;   case (15):     console.log("your age is 15")     break   case (18):     console.log("your age is 18")     break   default:     console.log("your age is not...

How to convert a string into number

 let a = "10"; a = Number.parseInt(a) console.log(a)

JavaScript Comparison and Logical Operators

 == is equal to  != is not equal to\ === to same hi h bs isme ham agar string lagadege to false a jaiga otherwise true !== not equal value and type && me hamari dono value same noni chaile like a = 5 b = 6 - a<b && a ==5 dono same h na || isme agar koi bhi 1 value true h to pura true ho jaiga else false 7 + 8 = 15 7 is operand + is operator and 15 is result -------------------------------------------------------------------------------------------- --- let a = 5; let b = 10; console.log("a == b is", a == b) console.log("a != b is", a != b) console.log("a === b is", a === b) console.log("a !== b is", a !== b)

craete a dictonary very beegner level codewitharry

 const dict = {   nav : "navjot",   sin: "singh",   sad: "sadhana", } console.log(dict.sad)

Accept an integer and Print hello world n times in loop

  // Accept an integer and Print hello world n times let a = Number ( prompt ( "enter the number" )) for ( let i = 0 ; i < a ; i ++ ){     console . log ( "hello world" ) }

for in loop

let student = {   name: "rahul kumar",   age: 20, cgpa: 7.5, ispass : true, } for (let key in student){   console.log("key=", key, "value=", student[key] ) }

How to create Even number 1 to 100 with for loop

  for(var i = 0; i <= 100; i++){  if (i % 2 === 0){     console.log(i)   } }

How to create odd number 1 to 100 with for loop

 for(var i = 0; i <= 100; i++){   if (i % 2 !== 0){     console.log(i)   } }