scrimba
Note at 0:00
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:00
AboutCommentsNotes
Note at 0:00
Expand for more info
index.js
run
preview
console
/* 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"
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"))

Console
/index.html
LIVE