Example output: "HELLO!"
Example input: "I'm almost out of coffee"
Example output: "I'M 😱 ALMOST 😱 OUT 😱 OF 😱 COFFEE!"
*/
const textInput = document.querySelector(".text-input");
const displayContainer = document.querySelector(".display-container");
let panicMode = false
const updateText = (text) => {
displayContainer.textContent = panicMode?panic(text):text;
}
const panic = (text) => text.split(" ").join(" 😱 ").toUpperCase();
const togglePanicMode = () => {
if (textInput.value){
panicMode = !panicMode;
document.body.classList.toggle("panic");
}
}
textInput.addEventListener('keyup',(e) => updateText(e.target.value))
document.getElementById("panic-btn").addEventListener('click',() => {
togglePanicMode();
updateText(textInput.value);
})
// Test your function
// console.log(panic("I'm almost out of coffee"));
// console.log(panic("winter is coming"))
/* Panic function
Write a PANIC! function. The function should take in a sentence and return the same
sentence in all caps with an exclamation point (!) at the end. Use JavaScript's
built in string methods.
If the string is a phrase or sentence, add a 😱 emoji in between each word.
Example input: "Hello"