Programs
Programs
3. Create an object student with properties: name (string), grade (number), subjects
(array), displayInfo() (method to log the student’s details) Write a script to dynamically add a
passed property to the student object, with a value of true or false based on their grade. Create a
loop to log all keys and values of the student object.
PROGRAM:
let student = {
name: "John Doe",
grade: 85,
subjects: ["Math", "Science", "English"],
displayInfo: function() {
console.log(`Name: ${this.name}`);
console.log(`Grade: ${this.grade}`);
console.log(`Subjects: ${this.subjects.join(', ')}`);
}
};
Open the vscode integrated terminal through the menu by selecting and type the below
command to run the program.
node index.js
OUTPUT:
Open index.html file in vscode and copy the below code paste it into that file, save it.
PROGRAM:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Listeners Example</title>
<style>
img {
width: 200px;
height: 140px;
border: 5px solid black;
margin-top: 10px;
}
button {
padding: 5px 10px;
background: #000;
color: #fff;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<img id="myImage"
src="https://vtucircle.com/wp-content/uploads/2025/01/Full-Stack-Development-
BIS601.jpg">
<script>
const button = document.getElementById('myButton');
button.addEventListener('click', function () {
console.log('Button clicked!');
});
const image = document.getElementById('myImage');
image.addEventListener('mouseover', function () {
image.style.borderColor = 'red';
});
</html>
Install live server extension to see the visual output (It’s recommended).
OUTPUT:
BIS601 Program 5
5. Build a React application to track issues. Display a list of issues (use static data). Each issue
should have a title, description, and status (e.g., Open/Closed). Render the list using a functional
component.
Before you start, ensure you have Node.js and npm (Node Package Manager) installed on your
machine.
node -v
npm -v
Once the process is complete, you’ll see a folder named issue-tracker in your
directory. Navigate into the folder:
cd issue-tracker
Modify the app by editing src/App.js copy the below code and paste it, save it.
Modify the app by editing src/App.css copy the below code and paste it, save it.
App.js:
const issues = [
{
id: 1,
title: "Bug in login page",
description: "The login page throws an error when submitting invalid
credentials.",
status: "Open",
},
{
id: 2,
title: "UI glitch on homepage",
description: "There is a UI misalignment issue on the homepage for smaller
screens.",
status: "Closed",
},
{
id: 3,
title: "Missing translation for settings page",
description: "The settings page is missing translations for the Spanish
language.",
status: "Open",
},
{
id: 4,
title: "Database connection error",
description: "Intermittent database connection issue during peak hours.",
status: "Open",
},
];
App.css:
.App {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}
h1 {
color: #333;
}
.issue-list {
display: flex;
flex-direction: column;
align-items: center;
}
.issue {
background-color: #f9f9f9;
border: 1px solid #ccc;
border-radius: 5px;
padding: 15px;
margin: 10px;
width: 80%;
max-width: 600px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.issue h3 {
margin: 0 0 10px;
font-size: 1.5em;
}
.issue p {
margin: 0 0 10px;
color: #555;
}
.status {
font-weight: bold;
}
.status.open {
color: #e74c3c;
}
.status.closed {
color: #2ecc71;
}
npm start
This will start a local development server and automatically open your new React application in
your default web browser. The server will reload the page automatically whenever you make
changes to your code.
OUTPUT:
BIS601 Program 6
6. Create a component Counter with A state variable count initialized to 0. Create Buttons to
increment and decrement the count. Simulate fetching initial data for the Counter component
using useEffect (functional component) or componentDidMount (class component). Extend the
Counter component to Double the count value when a button is clicked. Reset the count to 0
using another button.
After creating successfully then change the directory using below command.
cd counter-app
Create two separate file Counter.js and CounterClass.js inside the src folder.
After then copy the below code and paste within the respective
file Counter.js and CounterClass.js
After then Modify the App.js file present in the src folder. Copy the below code and paste it.
After then Modify the App.css file present in the src folder. Copy the below code and paste
it.
Counter.js:
useEffect(() => {
console.log('Fetching initial data...');
}, []);
return (
<div>
<h1>Count: {count}</h1>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
<button onClick={doubleCount}>Double</button>
<button onClick={resetCount}>Reset</button>
</div>
);
};
CounterClass.js:
componentDidMount() {
console.log('Fetching initial data...');
}
increment = () => {
this.setState(prevState => ({ count: prevState.count + 1 }));
};
decrement = () => {
this.setState(prevState => ({ count: prevState.count - 1 }));
};
doubleCount = () => {
this.setState(prevState => ({ count: prevState.count * 2 }));
};
resetCount = () => {
this.setState({ count: 0 });
};
render() {
return (
<div>
<h1>Count: {this.state.count}</h1>
<button onClick={this.increment}>Increment</button>
<button onClick={this.decrement}>Decrement</button>
<button onClick={this.doubleCount}>Double</button>
<button onClick={this.resetCount}>Reset</button>
</div>
);
}
}
function App() {
return (
<div className="App">
<h1 className='head'>Welcome to the Counter App</h1>
<Counter />
</div>
);
}
App.css:
.App {
border-radius: 7px;
background: #ffeaea;
text-align: center;
}
#root {
margin: 20px auto;
width: 40%;
height: 400px;
}
h1 {
color: #fff;
font-size: 25px;
border-radius: 6px;
margin: 20px auto;
background: #000000;
width: fit-content;
padding: 10px 60px;
}
.head {
width: 100%;
font-size: 25px;
margin: 0;
border-radius: 6px;
color: #fff;
background: #000000;
padding: 10px 0;
}
button {
margin: 10px;
padding: 8px 10px;
font-size: 16px;
border: none;
font-weight: 600;
border-radius: 5px;
cursor: pointer;
background: #e02020;
color: #fff;
}
Now, you can start the development server by using below command:
npm start
This will start a local development server and automatically open your new React application in
your default web browser. The server will reload the page automatically whenever you make
changes to your code.
OUTPUT: