All Exp
All Exp
Home Page
Login Page
Registration Page
About Institution
<!DOCTYPE html>
<html>
<head>
<title>Simple Education Website</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
/* Navigation */
nav {
background: #1a73e8;
padding: 15px;
}
nav a {
color: white;
text-decoration: none;
margin: 0 15px;
}
/* Sections */
.section {
padding: 50px 20px;
text-align: center;
}
/* Home Page */
#home {
background: #f0f4f8;
}
/* Forms */
.form-box {
width: 300px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
input {
width: 100%;
padding: 8px;
margin: 5px 0;
box-sizing: border-box;
}
button {
background: #1a73e8;
color: white;
padding: 10px;
border: none;
width: 100%;
margin-top: 10px;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav>
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#login">Login</a>
<a href="#register">Register</a>
</nav>
<!DOCTYPE html>
<html>
<head>
<title>College Management System</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
/* Navigation */
nav {
background: #2c3e50;
padding: 15px;
position: sticky;
top: 0;
}
nav a {
color: white;
text-decoration: none;
margin: 0 15px;
}
/* Sections */
.section {
padding: 30px 20px;
margin: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
/* Department Cards */
.dept-card {
background: #f9f9f9;
padding: 15px;
margin: 10px 0;
border-left: 4px solid #3498db;
}
/* Faculty Cards */
.faculty-card {
background: #ecf0f1;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
}
/* Student Info */
.student-info {
background: #f0f8ff;
padding: 20px;
margin: 10px 0;
}
/* Placement Staff */
.placement-staff {
background: #e8f5e9;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
}
</style>
</head>
<body>
<nav>
<a href="#departments">Departments</a>
<a href="#faculty">Faculty</a>
<a href="#student">Student Info</a>
<a href="#placement">Placement</a>
</nav>
/* Navigation */
nav {
background: #2c3e50;
padding: 15px;
position: sticky;
top: 0;
}
nav a {
color: white;
text-decoration: none;
margin: 0 15px;
}
/* Sections */
.section {
padding: 30px 20px;
margin: 20px;
}
/* Academic Info */
.academic-info {
background: #f0f8ff;
padding: 20px;
border-left: 4px solid #3498db;
margin: 10px 0;
}
/* Placement Card */
.placement-card {
background: #e8f5e9;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
}
<div class="placement-card">
<h3>Placement Statistics</h3>
<p>Total Offers: 120+</p>
<p>Highest Package: ₹18 LPA</p>
</div>
</div>
<div class="chapter-card">
<h3>Entrepreneurship Cell</h3>
<p><strong>Coordinator:</strong> Dr. Anita Sharma</p>
<p><strong>Activities:</strong> Startup Competitions, Mentorship</p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Simple Login Page</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f2f5;
}
.login-container {
background-color: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h2 {
text-align: center;
color: #1c1e21;
margin-bottom: 20px;
}
.input-group {
margin-bottom: 15px;
}
input {
width: 100%;
padding: 12px;
margin-top: 8px;
border: 1px solid #dddfe2;
border-radius: 6px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 12px;
background-color: #1877f2;
color: white;
border: none;
border-radius: 6px;
font-weight: bold;
cursor: pointer;
}
button:hover {
background-color: #166fe5;
}
.links {
text-align: center;
margin-top: 15px;
}
a{
color: #1877f2;
text-decoration: none;
font-size: 14px;
}
a:hover {
text-decoration: underline;
}
.signup-link {
display: block;
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form>
<div class="input-group">
<input type="text" placeholder="Username" required>
</div>
<div class="input-group">
<input type="password" placeholder="Password" required>
</div>
<div class="links">
<a href="#">Forgot Password?</a>
</div>
<div class="signup-link">
<span>Don't have an account? </span>
<a href="#">Sign Up</a>
</div>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Simple Form Validation</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 400px;
margin: 50px auto;
padding: 20px;
}
.form-group {
margin-bottom: 15px;
}
input {
width: 100%;
padding: 8px;
margin-top: 5px;
}
.error {
color: red;
font-size: 0.9em;
margin-top: 5px;
}
button {
padding: 10px 20px;
background: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<!-- Login Form -->
<h2>Login</h2>
<form id="loginForm" onsubmit="return validateLogin()">
<div class="form-group">
<label>Email:</label>
<input type="text" id="loginEmail">
<div class="error" id="loginEmailError"></div>
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" id="loginPassword">
<div class="error" id="loginPasswordError"></div>
</div>
<button type="submit">Login</button>
</form>
function clearErrors() {
document.querySelectorAll('.error').forEach(error => {
error.textContent = '';
});
}
// Login Validation
function validateLogin() {
clearErrors();
let isValid = true;
if (!emailRegex.test(email)) {
showError('loginEmailError', 'Invalid email address');
isValid = false;
}
if (password.length < 6) {
showError('loginPasswordError', 'Password must be at least 6 characters');
isValid = false;
}
if (isValid) {
alert('Login successful!');
return true;
}
return false;
}
// Registration Validation
function validateRegistration() {
clearErrors();
let isValid = true;
if (!nameRegex.test(name)) {
showError('nameError', 'Invalid name (letters and spaces only)');
isValid = false;
}
if (!emailRegex.test(email)) {
showError('emailError', 'Invalid email address');
isValid = false;
}
if (!passwordRegex.test(password)) {
showError('passwordError', 'Password must be 6+ characters with at least 1 letter and 1
number');
isValid = false;
}
if (isValid) {
alert('Registration successful!');
return true;
}
return false;
}
</script>
</body>
</html>
(6) Set up Node.js development environment and run sample console
programs.
Install Node.js on computer?
Expected Output:
Hello from Node.js!
Current time: 3:45:12 PM
Handle "Command not found" errors
Use it in app.js:
javascript
const _ = require('lodash');
const numbers = [1, 2, 3, 4];
console.log(_.sum(numbers)); // Output: 10
Math Module
File: mathUtils.js
javascript
// Add two numbers
const add = (a, b) => a + b;
// Subtract two numbers
const subtract = (a, b) => a - b;
String Module
File: stringUtils.js
javascript
// Reverse a string
const reverse = (str) => str.split('').reverse().join('');
// Import modules
const math = require('./mathUtils');
const string = require('./stringUtils');
node app.js
Usage in app.js:
javascript
Key Concepts:
1. module.exports: Export functions/objects from a file
2. require(): Import modules into other files
3. File Structure:
project-folder/
├── mathUtils.js
├── stringUtils.js
├── greet.js
└── app.js
Key Files/Folders
my-first-app/
├── node_modules/ # Dependencies
├── public/ # Static assets
├── src/ # React components
│ ├── App.js
│ └── index.js
├── package.json # Project config
└── package-lock.json
Basic Commands
Command Description
2. Install dependencies
bash
npm install react react-dom
npm install --save-dev webpack webpack-cli webpack-dev-server babel-loader
@babel/core @babel/preset-env @babel/preset-react
3. Create webpack.config.js
javascript
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
}
};
4. Create .babelrc
json
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
Troubleshooting
1. Clear npm cache if needed:
bash
npm cache clean --force
function App() {
return (
<div>
<ChildComponent message="Hello from Parent!" user={{ name: "Alice", age:
25 }} />
</div>
);
}
Key Points:
Props are read-only
Passed from parent to child
Can be strings, numbers, objects, or functions
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
);
}
Key Points:
State is mutable using setState or state setters
Created with useState hook
Triggers re-render when updated
return (
<div>
<Counter
currentCount={parentCount}
updateCount={setParentCount}
/>
</div>
);
}
Child (Counter.js):
javascript
function Counter({ currentCount, updateCount }) {
return (
<div>
<p>Parent Count: {currentCount}</p>
<button onClick={() => updateCount(currentCount + 1)}>
Update Parent Count
</button>
</div>
);
}
Key Differences
Props State
Immutable Mutable
Rules to Remember
1. Never modify props directly
2. Use state for values that change over time
3. Lift state up for shared data between components
4. Use prop-types for type checking
function TextForm() {
const [name, setName] = useState('');
return (
<form onSubmit={handleSubmit}>
<label>
Name:
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
/>
</label>
<button type="submit">Submit</button>
</form>
);
}
function MultiInputForm() {
const [formData, setFormData] = useState({
email: '',
password: '',
rememberMe: false
});
<input
type="password"
name="password"
placeholder="Password"
value={formData.password}
onChange={handleChange}
/>
<label>
<input
type="checkbox"
name="rememberMe"
checked={formData.rememberMe}
onChange={handleChange}
/>
Remember me
</label>
<button type="submit">Login</button>
</form>
);
}
function SelectForm() {
const [selectedOption, setSelectedOption] = useState('');
return (
<form>
<label>
Choose a course:
<select
value={selectedOption}
onChange={(e) => setSelectedOption(e.target.value)}
>
<option value="">Select...</option>
<option value="react">React</option>
<option value="node">Node.js</option>
<option value="python">Python</option>
</select>
</label>
<p>Selected: {selectedOption}</p>
</form>
);
}
function RadioForm() {
const [gender, setGender] = useState('');
return (
<form>
<label>
<input
type="radio"
value="male"
checked={gender === 'male'}
onChange={(e) => setGender(e.target.value)}
/>
Male
</label>
<label>
<input
type="radio"
value="female"
checked={gender === 'female'}
onChange={(e) => setGender(e.target.value)}
/>
Female
</label>
5. Form Validation
javascript
function ValidatedForm() {
const [email, setEmail] = useState('');
const [error, setError] = useState('');
return (
<form onSubmit={handleSubmit}>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter email"
/>
{error && <div style={{ color: 'red' }}>{error}</div>}
<button type="submit">Submit</button>
</form>
);
}
Key Concepts:
4. Input Types:
o Text: <input type="text">