added other units

This commit is contained in:
Benjamin Adovasio
2025-11-16 22:54:34 -05:00
parent 5bd461229a
commit ca92b603be
46 changed files with 2779 additions and 0 deletions

21
Unit 4/Day 2/index.html Normal file
View File

@@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<title>Unit 4 Day 2</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Count "s" and "S" characters</h1>
<label for="input1">Input:</label>
<input type="text" id="input1"></input>
<button onclick="program1(document.getElementById('input1').value)">Submit</button>
<p>Output: <p id="out1"></p></p>
<hr>
<h1>Capitalize every odd number letter and lowercase every even number letter</h1>
<label for="input2">Input:</label>
<input type="text" id="input2"></input>
<button onclick="program2(document.getElementById('input2').value)">Submit</button>
<p>Output: <p id="out2"></p></p>
<script src="script.js"></script>
</body>
</html>

35
Unit 4/Day 2/script.js Normal file
View File

@@ -0,0 +1,35 @@
function program1(inputString){
document.getElementById("out1").innerHTML="";
let inputArray = Array.from(inputString);
let regex = /s/gm;
let counter = 0;
for (i = 0; i < inputArray.length; i++) {
if (regex.test(inputArray[i])) {
counter++;
}
else {
console.log("not an s");
}
}
document.getElementById("out1").innerHTML=counter;
}
function program2(inputString){
document.getElementById("out2").innerHTML="";
let inputArray = Array.from(inputString);
for (i = 0; i < inputArray.length; i++) {
if (i % 2 == 0) {
console.log("odd");
let outputCharacter = inputArray[i].toUpperCase();
let existingText = document.getElementById("out2").textContent;
document.getElementById("out2").innerHTML= existingText + outputCharacter;
}
else {
console.log("not an s");
let outputCharacter = inputArray[i].toLowerCase();
let existingText = document.getElementById("out2").textContent;
document.getElementById("out2").innerHTML= existingText + outputCharacter;
}
}
// document.getElementById("out1").innerHTML= localStorage;
}

0
Unit 4/Day 2/style.css Normal file
View File