Check a array for bad words? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Check a array for bad words?

Hello! I just made a code wich will check if the user input has bad words. As you can see, the bad words are in a array and the only word that is being blocked is the 3rd one, "cu". http://code.sololearn.com/WyWCarn692iw/#js As it seems, my code is not searching all the words in the array, but taking the last one. Thanks!

21st Sep 2016, 8:47 PM
Scotti
Scotti - avatar
3 Antworten
+ 1
hi add : -> break; at the end of the if bloc; and your test condition only needs : -> if (pegaTexto.value.toLowerCase() === ofensa[i])
21st Sep 2016, 9:26 PM
ADEL MAHJOUB
ADEL MAHJOUB - avatar
+ 1
if (pegaTexto.value.toLowerCase() === ofensa[i]) { document.getElementById('alerta').style.display = "block"; document.getElementById('alerta').style.backgroundColor=#ff0000"; document.getElementById('alerta').innerHTML = alertaTextoErr; break; }
21st Sep 2016, 9:31 PM
ADEL MAHJOUB
ADEL MAHJOUB - avatar
0
Thank you for the help, it works fine now!!!
21st Sep 2016, 9:36 PM
Scotti
Scotti - avatar