Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ form {
border: 1px solid black;
padding: 20px;
background-color: beige;
}
}

38 changes: 35 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<link rel="stylesheet" href="./index.css">
<title>Combining HTML and JavaScript + DOM Lab</title>
<script src="./index.js" defer>
</script>
</head>
<body>
<h1 id = "top_heading">Combining HTML and JavaScript + DOM Lab</h1>
Expand All @@ -16,38 +18,68 @@ <h2>1. String Mirror</h2>

<input id="mirror-input" type="text" placeholder="Enter your string here">
<p id="mirror-output">Waiting for input...</p>
<button id="mirror-button" type="submit">Submit</button>
<button onclick="displayString()" id="mirror-button" type="submit">Submit</button>


<h2>2. String Uppercaser</h2>

<li>Make a text input with id='uppercaser-input'</li>
<li>They should then be able to click a "submit" button with id='uppercaser-button' that will display the string the user entered in all uppercase in an element with id='uppercaser-output'</li>

<input id="uppercaser-input" type="text" placeholder="Enter your string here">
<p id="uppercaser-output">Waiting for input...</p>
<button onclick="displayUppercase()" id="uppercaser-button" type="submit">Submit</button>


<h2>3. Palindrome Detector</h2>

<li>The user should be able to enter a string into a text input with id='palindrome-input'</li>
<li>They should then be able to click a "submit" button with id='palindrome-button'. Clicking the button will display a string in the form "It is ${true/false} that ${entered string} is a palindrome" with id='palindrome-output'</li>

<input id="palindrome-input" type="text" placeholder="Enter your string here">
<p id="palindrome-output">Waiting for input...</p>
<button onclick="displayPalindrome()" id="palindrome-button" type="submit">Submit</button>


<h2>4. Even Checker</h2>

<li>The user should be able to enter a number into an input with id='even-checker-input'</li>
<li>They should then be able to click a "submit" button with id='even-checker-button' that will display a string in the form "It is ${true/false} that ${entered number} is even" with id='even-checker-output'</li>

<input type="number" id="even-checker-input" placeholder="Enter a number here.">
<p id="even-checker-output">Waiting for input...</p>
<button onclick="checkEvenNum()" id="even-checker-button" type="submit">Submit</button>

<h2>5. Number Doubler</h2>

<li>The user should be able to enter a number into an input with id='doubler-input'</li>
<li>They should then be able to click a "submit" button with id='doubler-button' that will display a string in the form "${entered number} doubled is ${doubledVal}" with id='doubler-output'</li>

<input type="number" id="doubler-input" placeholder="Enter a number here.">
<p id="doubler-output">Waiting for input...</p>
<button onclick="getDoubleNum()" id="doubler-button" type="submit">Submit</button>

<h2>6. Average of Three Numbers</h2>

<li>The user should be able to enter 3 numbers into text inputs with ids 'average-input-1', 'average-input-2', and 'average-input-3'</li>
<li>They should then be able to click a "submit" button with id='average-button' that will display a string in the form "The average of ${numberOne}, ${numberTwo}, and ${numberThree} is ${average}" with id='average-output'</li>


<input type="number" id="average-input-1" placeholder="Enter a number here.">
<input type="number" id="average-input-2" placeholder="Enter a number here.">
<input type="number" id="average-input-3" placeholder="Enter a number here.">
<p id="average-output">Waiting for input...</p>
<button onclick="getThreeNumAvg()" id="average-button" type="submit">Submit</button>

<h2>Bonus: Vowel Remover</h2>

<li>The user should be able to enter a string into a text input with id='vowel-remover-input'</li>
<li>The user should be able to select or deselect a checkbox with id='y-is-vowel-checkbox'</li>
<li>They should then be able to click a "submit" button with id='vowel-remover-button' that will display the original string with all vowels removed with id='vowel-remover-output'. If the checkbox is checked, count y as a vowel. Otherwise, count y as a consonant.</li>

<input type="text" id="vowel-remover-input" placeholder="Enter a string here">
<input type="checkbox" id="y-is-vowel-checkbox" name="y-is-vowel-checkbox">
<label for="y-is-vowel-checkbox">Y is a vowel</label>
<p id="vowel-remover-output">Waiting for input...</p>
<button onclick="removeVowel()" id="vowel-remover-button" type="submit">Submit</button>
</body>
</html>

67 changes: 67 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const displayString = () => {
const input = document.querySelector("#mirror-input").value;
const output = document.querySelector("#mirror-output");
output.innerText = `${input}`;
};

const displayUppercase = () => {
const input = document.querySelector("#uppercaser-input").value;
const output = document.querySelector("#uppercaser-output");
output.innerText = `${input.toUpperCase()}`;
};

const displayPalindrome = () => {
const input = document
.querySelector("#palindrome-input")
.value.toLowerCase()
.split("")
.join("");
const output = document.querySelector("#palindrome-output");
let i = 0;
let j = input.length - 1;
while (i < j) {
if (input[i] !== input[j]) {
return (output.innerText = `It is false that ${input} is a palindrome.`);
}
i++;
j--;
}
return (output.innerText = `It is true that ${input} is a palindrome.`);
};

const checkEvenNum = () => {
const input = document.querySelector("#even-checker-input").value;
const output = document.querySelector("#even-checker-output");
if (input % 2 === 0) {
output.innerText = `It is true that ${input} is even`;
} else {
output.innerText = `It is false that ${input} is even`;
}
};

const getDoubleNum = () => {
const input = document.querySelector("#doubler-input").value;
const output = document.querySelector("#doubler-output");
const numDub = input * 2;
output.innerText = `${input} doubled is ${numDub}`;
};

const getThreeNumAvg = () => {
const numOne = Number(document.querySelector("#average-input-1").value);
const numTwo = Number(document.querySelector("#average-input-2").value);
const numThree = Number(document.querySelector("#average-input-3").value);
const output = document.querySelector("#average-output");
const avgThreeNum = (numOne + numTwo + numThree) / 3;
output.innerText = `The average of ${numOne}, ${numTwo}, and ${numThree} is ${avgThreeNum}`;
};

const removeVowel = () => {
const string = document.querySelector("#vowel-remover-input").value;
const checkbox = document.querySelector("#y-is-vowel-checkbox");
const output = document.querySelector("#vowel-remover-output");
if (checkbox.checked) {
output.innerText = string.replace(/a|e|i|o|u|y/gi, "");
} else {
output.innerText = string.replace(/a|e|i|o|u/gi, "");
}
};
Loading