Full Stack Development-BIS601 Lab Manual
Full Stack Development-BIS601 Lab Manual
Lab Manual
Code:
// Sum calculation
function sum(a, b) {
return a + b;
}
alert("The sum is: " + sum(5, 10));
Execution Steps:
Code:
// City array
let cities = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"];
Code:
let userInput = prompt("Enter a string:");
console.log("Length of the string: " + userInput.length);
// Extract "JavaScript"
let extractedWord = userInput.substring(0, 10); // Adjust indices as needed
console.log("Extracted word: " + extractedWord);
// Replace word
let newString = userInput.replace("oldWord", "newWord");
console.log("New string: " + newString);
Execution Steps:
Code:
function isPalindrome(str) {
let reversedStr = str.split('').reverse().join('');
return str === reversedStr;
}
console.log(isPalindrome("madam")); // true
console.log(isPalindrome("hello")); // false
Execution Steps:
Code:
let student = {
name: "John Doe",
grade: 90,
subjects: ["Math", "Science", "English"],
displayInfo: function() {
console.log(`Name: ${this.name}, Grade: ${this.grade}, Subjects:
${this.subjects.join(", ")}`);
}
};
student.displayInfo();
Execution Steps:
Code:
1. Add the above code to the studentObject.js file after the previous code.
2. Save the file.
3. Run the file again in the console or using Node.js.
HTML:
document.getElementById("myButton").addEventListener("click", function() {
console.log("Button clicked!");
});
Execution Steps:
HTML:
document.getElementById("myImage").addEventListener("mouseover", function() {
this.style.borderColor = "red";
});
Execution Steps:
1. Add the above HTML and JavaScript code to the buttonEvent.html file.
2. Ensure you have an image file named image.jpg in the same directory.
3. Save the file.
4. Open the file in a web browser and hover over the image to see the border change.
JavaScript:
document.addEventListener("keypress", function(event) {
console.log("Key pressed: " + event.key);
});
Execution Steps:
1. Add the above JavaScript code to the buttonEvent.html file within the <script> tag.
2. Save the file.
3. Open the file in a web browser and press any key to see the logged message in the
console.
5. React Application for Issue Tracking
Code:
const issues = [
{ title: "Issue 1", description: "Description 1", status: "Open" },
{ title: "Issue 2", description: "Description 2", status: "Closed" },
];
function IssueList() {
return (
<div>
<h1>Issue Tracker</h1>
<ul>
{issues.map((issue, index) => (
<li key={index}>
<h2>{issue.title}</h2>
<p>{issue.description}</p>
<p>Status: {issue.status}</p>
</li>
))}
</ul>
</div>
);
}
Execution Steps:
1. Set up a new React project using Create React App: npx create-react-app issue-tracker.
2. Navigate to the project directory: cd issue-tracker.
3. Replace the contents of src/App.js with the above code.
4. Save the file.
5. Start the development server: npm start.
6. Open the browser to http://localhost:3000 to see the issue list.
Code:
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<h1>Count: {count}</h1>
<button onClick={() => setCount(count + 1)}>Increment</button>
<button onClick={() => setCount(count - 1)}>Decrement</button>
</div>
);
}
Code:
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Execution Steps:
Code:
1. Add the above code to your server.js file after the existing code.
2. Ensure you have middleware to parse JSON: app.use(express.json());.
3. Save the file.
4. Test the API using Postman or a similar tool to send GET and POST requests.
8. MongoDB Integration with Node.js
Code:
Code: