Capitalize First Word
This project filters string and capitalizes the first character after a period
by Neil Daley
HTML
<div id="res"></div>
<div id="result"></div>
JavaScript
/*
function capitalizeSentences(str) {
const sentences = str.split(', ');
sentences.forEach((sentence, index) => {
sentences[index] = sentence.charAt(0).toUpperCase() + sentence.slice(1);
});
return sentences.join(', ');
}
//const inputString = "hello. how are you? i am fine.";
const inputString = "engineering, liDAR, other Links, stormwater, stormwater/CM&E";
const capitalizedString = capitalizeSentences(inputString);
//console.log(capitalizedString);
document.getElementById('result').innerText = capitalizedString
*/
/*
function separateString() {
// Input string
var originalString = "One, Two, Three, Four, Five";
var found = false;
// Converted array
var separatedArray = originalString.split(', ');
var findWord = "Two";
if (separatedArray == findWord) {
found = true;
document.getElementById('result').innerText = separatedArray
document.getElementById('result').innerText = "Found"
}
// Display output
console.log(separatedArray);
//document.getElementById('result').innerText = "Not found"
document.getElementById('res').innerText = separatedArray
document.getElementById('result').innerText = "Found"
}
separateString();
*/
// Example 1: Loop through an array and log the value of each element
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(function(number) {
//console.log(number);
document.getElementById('res').innerText = number
});
// Example 2: Loop through an array of objects and log a property of each object
const students = [
{ name: 'Alice', grade: 'A' },
{ name: 'Bob', grade: 'B' },
{ name: 'Charlie', grade: 'C' },
];
students.forEach(function(student) {
//console.log(student.name);
document.getElementById('res').innerText = student.name;
//document.getElementById('result').innerText = "Found"
});
// Example 3: Loop through the characters of a string and log each character
const sentence = 'SheCodes is awesome!';
const characters =...