Assignment 4
Assignment 4
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}`;
}
}
4.
class Animal {
makeSound() {
console.log("Some generic animal sound");
}
}
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
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">
<style>
body {
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>
</header>
<main>
<section>
<h2>Latest Articles</h2>
<article>
</article>
<article>
<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>
</footer>
</body>
</html>
OUTPUT:
Welcome to My Website
8.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Form</title>
<style>
body {
margin: 20px;
form {
max-width: 400px;
margin: auto;
input {
width: 100%;
padding: 10px;
margin: 10px 0;
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>
<label for="email">Email:</label>
<label for="birthdate">Birthdate:</label>
<button type="submit">Submit</button>
</form>
</body>
</html>