You are viewing a single comment's thread. Return to all comments →
anyone help me with what i am missing
import React, { useState } from "react";
const OMITTED_WORDS = ["a", "the", "and", "or", "but"];
function WordOmitter() { const [inputText, setInputText] = useState(""); const [omitWords, setOmitWords] = useState(true); const [ommitedWords, setOmmitedWords] = useState(''); const handleInputChange = (e) => { setInputText(e.target.value); OMITTED_WORDS.forEach((word) => { if (inputText.includes(word)) { const value = inputText.replace(word, ''); setOmmitedWords(value); } }); if (inputText === '') { setOmmitedWords(''); } };
const toggleOmitWords = () => { if (omitWords) { setOmmitedWords(inputText); } else { OMITTED_WORDS.forEach((word) => { if (inputText.includes(word)) { const value = inputText.replace(word, ''); setOmmitedWords(value); } }); } setOmitWords(!omitWords); };
const clearFields = () => { setInputText(''); setOmmitedWords(''); // TODO: Add your changes here };
const getProcessedText = () => { // TODO: Add your changes here if (ommitedWords.length > 0) { return ommitedWords; } else { return ommitedWords; }; };
return ( {omitWords ? "Show All Words" : "Omit Words"} Clear
export { WordOmitter };
Seems like cookies are disabled on this browser, please enable them to open this website
Word Omitter
You are viewing a single comment's thread. Return to all comments →
anyone help me with what i am missing
import React, { useState } from "react";
const OMITTED_WORDS = ["a", "the", "and", "or", "but"];
function WordOmitter() { const [inputText, setInputText] = useState(""); const [omitWords, setOmitWords] = useState(true); const [ommitedWords, setOmmitedWords] = useState(''); const handleInputChange = (e) => { setInputText(e.target.value); OMITTED_WORDS.forEach((word) => { if (inputText.includes(word)) { const value = inputText.replace(word, ''); setOmmitedWords(value); } }); if (inputText === '') { setOmmitedWords(''); } };
const toggleOmitWords = () => { if (omitWords) { setOmmitedWords(inputText); } else { OMITTED_WORDS.forEach((word) => { if (inputText.includes(word)) { const value = inputText.replace(word, ''); setOmmitedWords(value); } }); } setOmitWords(!omitWords); };
const clearFields = () => { setInputText(''); setOmmitedWords(''); // TODO: Add your changes here };
const getProcessedText = () => { // TODO: Add your changes here if (ommitedWords.length > 0) { return ommitedWords; } else { return ommitedWords; }; };
return ( {omitWords ? "Show All Words" : "Omit Words"} Clear
Output:
{getProcessedText()} ); }export { WordOmitter };