TUTORIAL SHEET - 7
TUTORIAL SHEET - 7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS String Functions - Ayush Mishra 22BCE2160</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1000px;
margin: 30px auto;
padding: 20px;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
.tutorial-header {
text-align: center;
margin-bottom: 20px;
padding: 15px;
background: #000080;
color: white;
border-radius: 10px;
font-size: 1.2em;
}
.header {
text-align: center;
margin-bottom: 30px;
padding: 20px;
background: #000080;
color: white;
border-radius: 10px;
}
.function-card {
background: white;
margin: 15px 0;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
h3 {
color: #2c3e50;
margin-top: 0;
}
.purpose {
color: #3498db;
font-weight: 500;
<div class="header">
<h1>JavaScript String Functions Demo</h1>
<p>Created by Ayush Mishra (22BCE2160)</p>
</div>
<div class="container">
<div class="function-card">
<h3>1. length Property</h3>
<div class="purpose">Returns the number of characters in a string</
div>
<code>name.length</code>
<div class="result" id="length"></div>
</div>
<div class="function-card">
<h3>2. toUpperCase()</h3>
<div class="function-card">
<h3>3. toLowerCase()</h3>
<div class="purpose">Converts all characters to lowercase</div>
<code>name.toLowerCase()</code>
<div class="result" id="lower"></div>
</div>
<div class="function-card">
<h3>4. slice()</h3>
<div class="purpose">Extracts part of the string</div>
<code>name.slice(6, 12)</code>
<div class="result" id="slice"></div>
</div>
<div class="function-card">
<h3>5. replace()</h3>
<div class="purpose">Replaces a substring with another</div>
<code>name.replace("Mishra", "Kumar")</code>
<div class="result" id="replace"></div>
</div>
<div class="function-card">
<h3>6. trim()</h3>
<div class="purpose">Removes whitespace from both ends</div>
<code>" Ayush Mishra 22BCE2160 ".trim()</code>
<div class="result" id="trim"></div>
</div>
<div class="function-card">
<h3>7. charAt()</h3>
<div class="purpose">Returns character at specified position</div>
<code>name.charAt(0)</code>
<div class="result" id="charAt"></div>
</div>
<div class="function-card">
<h3>8. split()</h3>
<div class="purpose">Splits the string into an array</div>
<code>name.split(" ")</code>
<div class="result" id="split"></div>
</div>
<div class="function-card">
<h3>9. concat()</h3>
<div class="function-card">
<h3>10. includes()</h3>
<div class="purpose">Checks if a string contains a substring</div>
<code>name.includes("Mishra")</code>
<div class="result" id="includes"></div>
</div>
</div>
<div class="footer">
Ayush Mishra 22BCE2160
</div>
<script>
const name = "Ayush Mishra 22BCE2160";
.header {
background-color: #003366;
color: white;
padding: 15px;
text-align: center;
border-radius: 8px;
margin-bottom: 20px;
}
.footer {
background-color: #003366;
color: white;
padding: 15px;
text-align: center;
border-radius: 8px;
margin-top: 20px;
}
.section {
margin-bottom: 30px;
background-color: #f5f5f5;
padding: 15px;
border-radius: 8px;
}
h2 {
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 5px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
.match {
color: #27ae60;
font-weight: bold;
}
.no-match {
color: #e74c3c;
font-weight: bold;
}
.regex {
font-family: monospace;
color: #c0392b;
}
.test-string {
font-family: monospace;
color: #2980b9;
}
</style>
</head>
<body>
<div class="header">
<h1>Tutorial 7 : Web Programming</h1>
</div>
<div id="container"></div>
<div class="footer">
Ayush Mishra 22BCE2160
</div>
<script>
const examples = [
{
category: 'Modifiers',
examples: [
{
function parseRegExp(regexStr) {
const parts = regexStr.split('/');
return new RegExp(parts[1], parts[2] || '');
}
function createDemoSection(categoryData) {
const section = document.createElement('div');
section.className = 'section';
categoryData.examples.forEach(example => {
const row = document.createElement('tr');
const regex = parseRegExp(example.regex);
const result = regex.test(example.testString);
row.innerHTML = `
<td class="regex">${example.regex}</td>
<td class="test-string">${example.testString.replace(/\n/g, '\\n')}</td>
<td class="${result ? 'match' : 'no-match'}">${result ? 'Match' : 'No
Match'}</td>
<td>${example.description}</td>
`;
table.appendChild(row);
});
section.appendChild(table);
return section;
}