am endeavoring to highlight a word upon clicking that does not adhere to the exception of the silent ‘e’ rule. Despite multiple attempts with various regex patterns, I consistently encounter the same outcome.
import { View, Text, SafeAreaView, ImageBackground,StatusBar,Image,Dimensions, TouchableOpacity,ScrollView, FlatList } from 'react-native'
import React,{useState,useContext} from 'react'
import style from '../theme/style'
import themeContext from '../theme/themeContex';
import { Colors } from '../theme/color';
import Icon from 'react-native-vector-icons/Ionicons'
import { AppBar,HStack, IconButton } from '@react-native-material/core';
// import { Avatar } from 'react-native-paper';
import Height from './Height';
import {Avatar} from 'react-native-elements';
import { useNavigation } from '@react-navigation/native';
import { color } from 'react-native-elements/dist/helpers';
import BackButton from './Componants/BackButton';
import Header from './Componants/Header';
const width =Dimensions.get('screen').width
const height = Dimensions.get('screen').height
// Regex pattern to determine if a word follows the silent "e" rule
// Regex pattern to determine if a word follows the silent "e" rule
const regex = /(?:[^aeiouy]|y$|a(?!i)|e(?!a)|(ia)|(ei)|(ie)|(eu)|(ui))$/;
const exceptions = [
"love", "move", "come", "rule", "give", "above", "done", "bone", "some",
"gate", "whole", "horse", "house", "mouse", "once",
];
// const regex = /[^aeiou]e(?=[a-z])/;
export default function RuleExceptions() {
const theme = useContext(themeContext);
const navigation = useNavigation();
const [darkMode, setDarkMode] = useState(false)
const [clickedWords, setClickedWords] = useState([]);
const handleClick = (word) => {
// Check if the word is an exception based on the regex pattern and exception list
const isException = !regex.test(word) && exceptions.includes(word); // Correct condition
// Update the clickedWords state with the clicked word and its exception status
if (clickedWords.find(w => w.word === word)) {
// Remove the word from the list if it's already clicked
setClickedWords(clickedWords.filter(w => w.word !== word));
} else {
// Add the word to the list with its exception status
setClickedWords([...clickedWords, { word, isException }]);
}
};
const words = [
'Have', 'Like', 'Love', 'Side', 'Done', 'Mute', 'Come', 'Rule',
'Gate', 'Above', 'Bake', 'Bike', 'Pole', 'Flute', 'Here', 'Some'
];
console.log("Regex pattern:", regex);
console.log("Exceptions:", exceptions);
console.log("Current clickedWords:", clickedWords);
return (
<SafeAreaView style={{flex:1, paddingTop:25}}>
<ImageBackground source={require('../../assets/image/read.png')}
style={{flex:1}}>
<StatusBar backgroundColor={"#C2EEFF"} translucent={true}/>
<Header />
<View style={{ paddingHorizontal:20,}}>
<Text style={{fontFamily:'BADABB', fontSize:21, color:'#E51F5C', textAlign:'center', width:'100%', letterSpacing:1, lineHeight:21,}}>Silent E – Rule Exceptions!</Text>
{/* <Text style={{fontFamily:'BADABB', fontSize:21, color:'#E51F5C', textAlign:'center', width:'100%', letterSpacing:1, lineHeight:21, marginBottom:15,}}>Aa and Ee Vowel Sounds</Text> */}
<Text style={{fontFamily:'Cheesecake', fontSize:18, color:'#000', textAlign:'center', width:'100%', letterSpacing:1, marginTop:10, lineHeight:20,}}>Highlight the words where Silent E does NOT follow the rule! </Text>
</View>
<View style={{paddingHorizontal:20, marginTop:20,}}>
<View style={{flexDirection:'row', flexWrap:'wrap', width:'100%', borderWidth:2, borderColor:'#0E73BB'}}>
{words.map((word, index) => (
<View key={index} style={{ width: '25%', borderWidth: 2, borderColor: '#0E73BB', borderBottomWidth: 2 }}>
<TouchableOpacity onPress={() => handleClick(word)}>
<Text style={{
paddingVertical: 5,
fontWeight: '600',
fontFamily: 'Cheesecake',
fontSize: 18,
textAlign: 'center',
backgroundColor: clickedWords.find(w => w.word === word)?.isException ? 'green' : 'transparent',
color: '#1C3014',
}}>{word}</Text>
</TouchableOpacity>
</View>
))}
</View>
</View>
<View style={{marginTop:20,}}>
<Text style={{fontFamily:'BADABB', fontSize:18, color:'#E51F5C', textAlign:'center', width:'100%', letterSpacing:1, lineHeight:21,}}>REMEMBER: Not all words will follow this rule. </Text>
<Text style={{fontFamily:'BADABB', fontSize:18, color:'#E51F5C', textAlign:'center', width:'100%', letterSpacing:1, lineHeight:21,}}>When you get to a silent E word, try to sound it out using BOTH vowel sounds to see what would make sense </Text>
</View>
<BackButton style={{width:'100%',}}/>
</ImageBackground>
</SafeAreaView>
)
}
below is the outcome of the above code
Current clickedWords: [{"isException": false, "word": "Have"}, {"isException": false, "word": "Done"}, {"isException": false, "word": "Gate"}, {"isException": false, "word": "Pole"}, {"isException": false, "word": "Flute"}, {"isException": false, "word": "Above"}, {"isException": false, "word": "Mute"}, {"isException": false, "word": "Like"}, {"isException": false, "word": "Love"}, {"isException": false, "word": "Come"}, {"isException": false, "word": "Bake"}, {"isException": false, "word": "Here"}, {"isException": false, "word": "Some"}, {"isException": false, "word": "Bike"}, {"isException": false, "word": "Rule"}, {"isException": false, "word": "Side"}]
I want the above code to highlight the word which is not following the rule