0% found this document useful (0 votes)
16 views8 pages

Assignment 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Assignment 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

ASSIGNMENT-4

1.
const multiply = (a, b) => a * b;
OUTPUT:
console.log(multiply(2, 3));
Outputs: 6
2.
const book = {
title: "The Great Gatsby",
author: "F. Scott Fitzgerald",
details: function() {
console.log(`Title: ${this.title}, Author: ${this.author}`);
}
};
book.details();
OUTPUT
Title: The Great Gatsby, Author: F. Scott Fitzgerald
3.
class Laptop {
constructor(brand, model) {
this.brand = brand;
this.model = model;
}

getDetails() {
return `Brand: ${this.brand}, Model: ${this.model}`;
}
}

const myLaptop = new Laptop("Apple", "MacBook Pro");


console.log(myLaptop.getDetails());
OUTPUT:
Brand: Apple, Model: MacBook Pro

4.

class Animal {
makeSound() {
console.log("Some generic animal sound");
}
}

class Dog extends Animal {


makeSound() {
console.log("Woof");
}
}

const myDog = new Dog();


myDog.makeSound();
OUTPUT:
Woof
5.
class Rectangle {
constructor(width, height) {
this.width = width;
this.height = height;
}

get area() {
return this.width * this.height;
}

set width(value) {
if (value > 0) {
this._width = value;
} else {
console.error("Width must be a positive number.");
}
}
get width() {
return this._width;
}
}
const myRectangle

OUTPUT:

Area: 50

New Width: 15

New Area: 75

Width must be a positive number.

6.

function Animal() {

this.eats = true;

function Dog() {

this.barks = true;

Dog.prototype = Object.create(Animal.prototype);

Dog.prototype.constructor = Dog;
const myDog = new Dog();

console.log("Eats:", myDog.eats);

console.log("Barks:", myDog.barks);

OUTPUT:

Eats: true

Barks: true

7.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Simple HTML5 Page</title>

<style>

body {

font-family: Arial, sans-serif;

line-height: 1.6;

margin: 0;

padding: 0;

header {

background: #4CAF50;

color: white;

padding: 1em 0;

text-align: center;

footer {

background: #333;
color: white;

text-align: center;

padding: 1em 0;

position: relative;

bottom: 0;

width: 100%;

section {

padding: 20px;

margin: 20px;

article {

background: #f4f4f4;

padding: 15px;

margin: 10px 0;

</style>

</head>

<body>

<header>

<h1>Welcome to My Website</h1>

<p>Your one-stop destination for awesome content!</p>

</header>

<main>

<section>

<h2>Latest Articles</h2>

<article>

<h3>Article Title 1</h3>


<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam non urna nec augue
egestas malesuada.</p>

</article>

<article>

<h3>Article Title 2</h3>

<p>Suspendisse potenti. Sed sit amet libero non justo lacinia malesuada ut non nunc.</p>

</article>

</section>

<section>

<h2>About Us</h2>

<article>

<h3>Our Mission</h3>

<p>We aim to provide quality content and engage with our community through informative
articles and resources.</p>

</article>

</section>

</main>

<footer>

<p>&copy; 2024 My Website. All rights reserved.</p>

</footer>

</body>

</html>

OUTPUT:

Welcome to My Website

Your one-stop destination for awesome content!

8.

<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Simple Form</title>

<style>

body {

font-family: Arial, sans-serif;

margin: 20px;

form {

max-width: 400px;

margin: auto;

input {

width: 100%;

padding: 10px;

margin: 10px 0;

border: 1px solid #ccc;

border-radius: 4px;

button {

background-color: #4CAF50;

color: white;

padding: 10px;

border: none;

border-radius: 4px;

cursor: pointer;

button:hover {

background-color: #45a049;

</style>
</head>

<body>

<h2>Registration Form</h2>

<form>

<label for="name">Name:</label>

<input type="text" id="name" name="name" placeholder="Enter your name" required>

<label for="email">Email:</label>

<input type="email" id="email" name="email" placeholder="Enter your email" required>

<label for="birthdate">Birthdate:</label>

<input type="date" id="birthdate" name="birthdate" required>

<button type="submit">Submit</button>

</form>

</body>

</html>

You might also like