Friday, 9 June 2023

JavaScript Fundamentals: A Beginner's Guide to the Basics || Learn JS

JavaScript is a widely used programming language that is primarily used for creating interactive web pages and web applications. Here are some basic concepts in JavaScript:

  1. Variables: Variables are used to store data values. In JavaScript, you can declare variables using the var, let, or const keywords. For example:

     
        var name = "John";
        let age = 25;
        const PI = 3.14;


2. Data types: JavaScript has several built-in data types, including numbers, strings, booleans, arrays, objects, and more. You don't need to explicitly declare the data type of a variable; JavaScript automatically assigns it based on the value assigned. For example:

     
         var number = 10;
        var name = "John";
        var isTrue = true;
        var colors = ["red", "blue", "green"];
        var person = { name: "John", age: 25 };
       

3. Operators: JavaScript supports various operators for performing arithmetic, assignment, comparison, logical operations, and more. For example:

 
         var sum = 5 + 3;
        var isGreater = (10 > 5);
        var result = (true && false);


4. Conditional statements: Conditional statements allow you to execute different blocks of code based on specified conditions. JavaScript includes if, else if, and else statements. For example:

    
         var num = 10;
        if (num > 0) {
          console.log("Positive number");
        } else if (num < 0) {
          console.log("Negative number");
        } else {
          console.log("Zero");
        }
       

5. Loops: Loops are used to repeatedly execute a block of code. JavaScript provides for, while, and do-while loops. For example:

 
            for (var i = 0; i < 5; i++) {
            console.log(i);
          }
         
          var j = 0;
          while (j < 5) {
            console.log(j);
            j++;
          }


6. Functions: Functions are reusable blocks of code that perform a specific task. You can define your own functions in JavaScript. For example:

 
           function greet(name) {
            console.log("Hello, " + name + "!");
          }
         
          greet("John");
         

Thursday, 8 June 2023

Most Important JavaScript programms || JS Programms

 Most Important JavaScript programms

 

          Get the length of an array:
        var length = array.length;
       
        Convert an array to a string:
        var string = array.join(',');
       
        Check if a variable is null or undefined:
        if (variable == null) {
          // variable is null or undefined
        }
       
        Remove an element from an array by its index:
        array.splice(index, 1);
       
        Convert a number to a string:
        var string = number.toString();
       
        Get the current URL of the page:
        var currentURL = window.location.href;
       
        Round a number to a specified decimal place:
        var roundedNumber = number.toFixed(decimalPlaces);
       
        Get the index of the first occurrence of an element in an array:
        var index = array.indexOf(element);
       
        Create a new object with specific properties from an existing object:
        var newObject = {
          property1: existingObject.property1,
          property2: existingObject.property2
        };
       
       

Wednesday, 7 June 2023

Most Important JavaScript Methods || JavaScript Practice

 JavaScript Methods 

 

             1. Remove all whitespace from a string:

             Ans:-

            var stringWithoutWhitespace = string.replace(/\s/g, '');

           2. Convert a string to an integer:

           Ans:-

            var integer = parseInt(string);

            3. Sort an array in ascending order:

             Ans:-

            array.sort(function(a, b) {
              return a - b;
            });

            4. Find the maximum value in an array:

            Ans:-

            var max = Math.max(...array);

            5. Find the minimum value in an array:

            Ans:-

            var min = Math.min(...array);


                                  Thanks for visiting



Tuesday, 6 June 2023

5 Basic JavaScript Methods || Most Important Methods


 
         1.  Check if a variable is an array:

            Ans .   Array.isArray(variable);
 
         2 . Convert a string to lowercase:

            Ans.   var lowercaseString = string.toLowerCase();
 
         3 . Generate a random number between a minimum and maximum value:

        Ans . var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
 
         4. Get the current date and time:

          Ans . var currentDate = new Date();
 
        5.  Check if a string contains a specific substring:

        Ans .  var containsSubstring = string.includes(substring);


3 Fun JavaScript Programs to Level Up Your Coding Skills || JS Projects

 

Sure! Here's an article featuring 3 JavaScript programs with code examples:

Title: 3 Fun JavaScript Programs to Level Up Your Coding Skills

Introduction:

JavaScript is a versatile programming language that can be used to build interactive web applications. If you're looking to sharpen your coding skills and have some fun along the way, here are 3 JavaScript programs that you can try out. Each program includes code examples to help you understand the implementation. Let's dive in!

  1. Number Guessing Game: The number guessing game is a classic program that challenges the user to guess a random number within a specified range. Here's an example implementation in JavaScript:

    
     let randomNumber = Math.floor(Math.random() * 100) + 1;
    let guessedNumber = prompt("Guess a number between 1 and 100:");

       if (guessedNumber == randomNumber) {
      console.log("Congratulations! You guessed the correct number.");
    } else {
      console.log("Oops! Better luck next time. The number was: "
       + randomNumber);
    }



  1. TODO List: Create a simple TODO list application that allows users to add and remove tasks. Here's an example implementation: 

             
                let todoList = [];
                   function addTask(task) {
                  todoList.push(task);
                }
                function removeTask(task) {
                  let index = todoList.indexOf(task);
                  if (index > -1) {
                    todoList.splice(index, 1);
                  }
                }

                addTask("Buy groceries");
                addTask("Finish homework");
                removeTask("Buy groceries");

                console.log(todoList);
                 // Output: ["Finish homework"]


  1. Palindrome Checker: A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. Check if a given word is a palindrome using JavaScript:

       
       function isPalindrome(word) {
         let reversedWord = word.split("").reverse().join("");
        return word === reversedWord;
      }

      console.log(isPalindrome("racecar")); // Output: true
      console.log(isPalindrome("hello")); // Output: false


Thanks for Visting Here ,.

Monday, 5 June 2023

5 Must-Have JavaScript Programs for Web Development || Learn JavaScript

 

  5 Must-Have JavaScript Programs for Web Development  

   

Introduction:

JavaScript is a versatile programming language that powers the interactivity and dynamic nature of modern websites. It is widely used by web developers to create engaging user interfaces, perform complex calculations, and manage data on the client-side. In this article, we will explore five essential JavaScript programs that every web developer should have in their toolkit. These programs will enhance your productivity, improve the user experience, and simplify common tasks in web development.


1. Form Validation:

Form validation is crucial for ensuring data integrity and improving user experience. JavaScript provides powerful tools for validating user input before it is submitted to the server. By writing custom JavaScript functions, you can perform real-time validation on form fields, such as checking for required fields, validating email addresses, and enforcing specific formats. This program will help you create forms that prevent erroneous data from being submitted, reducing the chances of user frustration and data corruption.


2. Image Sliders:

Image sliders or carousels are popular components in modern web design. They allow you to showcase multiple images or content in a visually appealing and interactive manner. JavaScript frameworks like jQuery or libraries like Swiper.js provide easy-to-use APIs for creating dynamic image sliders. With JavaScript, you can add features like auto-play, navigation controls, and smooth transitions, enhancing the visual appeal and engagement of your website.


3. Real-time Search:

Implementing a real-time search feature can greatly improve the user experience of websites with large amounts of data. JavaScript's event-driven nature makes it an ideal choice for creating dynamic search functionality. By binding JavaScript events to search input fields, you can trigger live searches as users type, updating the search results in real-time without needing to refresh the page. This program will help you create search interfaces that are fast, responsive, and user-friendly.


4. Drag-and-Drop Interactions:

Drag-and-drop functionality allows users to intuitively interact with web content by dragging elements and dropping them onto specific areas or targets. JavaScript provides native APIs like Drag and Drop API or popular libraries like interact.js, which simplify the implementation of drag-and-drop interactions. This program will enable you to create interactive interfaces where users can reorder lists, upload files by dragging them onto a designated area, or create custom workflows through intuitive drag-and-drop gestures.


5. Client-side Data Storage:

JavaScript also enables you to store and manage data on the client-side without relying solely on server-side databases. With the help of JavaScript APIs like Web Storage (localStorage and sessionStorage) or IndexedDB, you can store user preferences, cached data, or even create offline web applications. This program will help you harness the power of client-side data storage, improving performance, reducing server load, and enabling users to access your website even without an internet connection.


Conclusion:

JavaScript is a powerful programming language that empowers web developers to create rich, interactive, and engaging websites. By incorporating these five essential JavaScript programs into your web development toolkit, you can enhance user experience, improve productivity, and tackle common challenges efficiently. Whether you are validating forms, creating image sliders, implementing real-time search, enabling drag-and-drop interactions, or managing client-side data storage, JavaScript has you covered. So dive into these programs, unleash your creativity, and take your web development skills to new heights.

JavaScript Question Practice For Logic Building || JS QNA

 JavaScript Question Practice For Logic Building 


 Q .  Write a JavaScript program to check whether
         a given integer is within 20 of 100 or 400.
     solution
    function testhundred(x) {
      return ((Math.abs(100 - x) <= 20) ||
       (Math.abs(400 - x) <= 20));
    }
    console.log(testhundred(10));
    console.log(testhundred(90));
     

     Q .  Write a JavaScript program to check two given
     integers whether one is positive and another one is negative.  
    solution
    function check(a,b){
      if((a < 0 && b > 0) || a > 0 && b < 0) {
        return true ;
      }
      else{
        return false;
      }
    }
    console.log(check(2,2))
    console.log(check(2,-2))
    console.log(check(-2,2))
    console.log(check(-2,-2))
     
     Q. Write a JavaScript program to create another string
    by adding "Py" in front of a given string. If the given
    string begins with "Py" return the original string.
     Solution
    function string_check(str1) {
    if (str1 === null || str1 === undefined || str1.substring(0, 2) === 'Py')
      {
        return str1;
      }
      return "Py"+str1;
    }
   
    console.log(string_check("Python"));
    console.log(string_check("thon"));
   
    Q . Write a JavaScript program to remove a character at the
   specified position in a given string and return the modified string
    Solution
    function removestr(){
      let str1 = "Hi getcodr" ;
      let str2 = str1.replace('Hi ','') ;
      return str2 ;
    }
    console.log(removestr()) ;
   
    Q. Write a JavaScript program to create a new string from a
       given string by changing the position of the first and last
     characters. The string length must be broader than or equal to 1.
    Solution
      function first_last(str1){
      if(str1.length <= 1){
        return str1 ;
      }
      newstr = str1.substring(1, str1.length - 1) ;
      return (str1.charAt(str1.length - 1)) + newstr + str1.charAt(0) ;
    }
    console.log(first_last('ram'));

This is me