Posts

Showing posts from August, 2024

Practice Set in JavaScript

  //Question 1 : Write a program using prompt function to take input of age as a value from the user and // use alert to tell him if he can drive! /*let runAgain = true; const canDrive = (age) => {     return age >= 18 ? true : false; } while (runAgain) {     let age = prompt("Enter your age : ");     age = Number.parseInt(age);     if (canDrive(age)) {         alert("Yes you can drive");     }     else {         alert("You can not drive");     }     runAgain = confirm("Do you want to play again ?"); }*/ //Question 2 : In Question 1, use confirm to ask the user if he wants to see the prompt again //Solution of Question 2 is shown in above code. //Question 3 : In the previous question, use console.error to log the error if the age entered is negative. /*let runAgain = true; const canDrive = (age) => {     return age >= 18 ? true : false; } whi...

DOM, BOM and Window Object in JavaScript

  window . console . log ( window ); console . log ( document . body ) document . body . style . background = "yellow" ;

alert, prompt and confirm in JavaScript

Image
  alert ( "Enter the value of a" ); let a = prompt ( "Enter value of a : " , "522" ); a = Number . parseInt ( a ); //document.write("The value of a is : " + a); alert ( "You entered a of type " + ( typeof a )); let write = confirm ( "Do you want to write it to the page ?" ); if ( write ) {     document . write ( "You entered : " + a ); } else {     document . write ( "Please allow me to write" ); }

Console Object in JavaScript

  console . log ( "Hello" ); let a = 4 ; let b = 2 ; console . log ( a + b ); console . log ( console ); console . info ( "info" ); console . warn ( "warn" ); console . error ( "Error" ); console . assert ( "Error" != false ); console . assert ( "Error" == false ); console . time ( "forLoop" ); for ( let i = 0 ; i < 500 ; i ++ ) {     console . log ( 233 ); } console . timeEnd ( "forLoop" ); console . time ( "whileLoop" ); let i = 0 ; while ( i < 500 ) {     console . log ( 233 );     i ++ ; } console . timeEnd ( "whileLoop" );

Script Tag in JavaScript

Image
  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < meta http-equiv = "X-UA-Compatible" content = "ie=edge" >     < title > Title 24 </ title >     < link rel = "stylesheet" href = "style.css" type = "text/css" > </ head > < body >     Hello World     <!-- Advantages of using separate script file using src attribute of script tag         1. Separation of concerns         2. Browser Caching -->     < script src = "script.js" >         console . log ( "I am trying to be smart" ); //This will be ignored     </ script > </ body > </ html > script.js File console . log ( "Hello" ); let a = 4 ; let b = 2 ; console ....