added other units
This commit is contained in:
21
Unit 4/Day 2/index.html
Normal file
21
Unit 4/Day 2/index.html
Normal 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
35
Unit 4/Day 2/script.js
Normal 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
0
Unit 4/Day 2/style.css
Normal file
Reference in New Issue
Block a user