Next Gen Practice After Learning Javascript Refresher part from Udemy Course

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Javascript Refresher</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            text-decoration: none;
            list-style: none;
        }
    </style>
</head>

<body>
    <h1 id="head">Javascript Refresher Practice Set</h1>

</body>
<script>
//     Question 1
//     Create a function that takes two numbers as arguments and returns their sum using the arrow function syntax
//     function Sum(num1, num2) {
//         console.log(`Your Sum is ${num1 + num2}`);
//     }
//     Sum(1, 2);


//     Question 2
//     Declare a constant variable called "PI" and assign it the value of 3.14159.
//     let value = 3.14159;


//     Question 3
//     Create a class called "Person" with properties "name" and "age" and a method called "sayHi" that logs a message to the console saying "Hi, my name is [name] and I am [age] years old."
//     class Person {
//         callingTeacher(name, age) {
//             this.name = "Najaf Ali";
//             this.age = 18;
//         }
//         sayHi() {
//             console.log(`Hi, my name is ${this.name} and I am ${this.age} years old.`)
//         }
//     }

//     By Using class
//         class Person {
//         constructor(name, age) {
//             this.name = name;
//             this.age = age;
//         }

//         sayHello() {
//             console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
//         }
//     }
//     const person = new Person("Jhon", 18);
//     person.sayHello();


//     By Using object literal syntax

//     const person = {
//         name: "Najaf Ali",
//         website: "NetCoreLab",
//         life: "Zobia",
//         age: 18,
//         status: "Devoloper",
//         sayHello: function () {
//             console.log(`Myself ${this.name}.My Lifeline name is ${this.life} Basically My Website is ${this.website}. I am a ${this.status} last but not least my age is ${this.age}`)
//         }
//     }
//     person.sayHello();

//     Write a function that takes an array of numbers as an argument and returns the sum of all the even numbers in the array.

//     let arr = [21, 2, 2, 2, 2, 2, 2, 82, 92, 102];
//     let arr1 = [];
//     let i;
//     for (i = 0; i < arr.length; i++) {
//         if (arr[i] % 2 == 0) {
//             arr1.push(arr[i]);
//         }
//         else {
//             console.log("You give me a odd number")
//         }
//         return arr1;
//     }

//     Export & Import

//     function multiply(a, b) {
//         return a * b;
//     }
//     export { multiply };


//     import { multiply } from './main.js';
//     console.log(multiply(2, 3));

//     In JavaScript, you can export a default value from a module using the export default syntax.Here's an example of how to write a default export code in JavaScript:

//     export default function add(a, b) {
//         console.log(a + b);
//     }


//     import myFunction from './main.js'
//     console.log(myFunction(2, 3));

//     // For multiple default exports

//     export default function add(a, b) {
//         console.log(a + b);
//     }
//     export const pi = 3.14; //like calling by named data

//     import myFunction, { pi } from {./ main.js };
//     console.log(myFunction(2, 3), pi);

//     import * as utils from './utils.js';

//     console.log(utils.pi); // Output: 3.14
//     console.log(utils.multiply(2, 3)); // Output: 6
// In this example, we import all named exports from the utils.js file into an object called utils.We can then access the named exports using dot notation, like utils.pi and utils.multiply.

// I hope this helps! Let me know if you have any further questions.


// Inheritance In js

class Animal{
    constructor(){
        this.name="Najaf Ali";
    }
    constructor2(){
        this.class=8;
    }
}
class Dog extends Animal {
    speak(){
        console.log(`${this.name} barks`)
    }
}
let dog=new Dog();
dog.speak();
</script>

</html>

Comments