0
I want to create a from where some certain words are not allowed . Pls help
this code works with only “kill” how do I add more alphabets to it without create many var values . Thanks <label>nme</label> <input id="o" type="text" placeholder="your name" required> <button onclick="f()" > calculate </button> function f() { var o = "Kill"; var o = document.getElementById("o").value; if ( o == "Kill" ) { alert("cant you such name"); } else { alert("ok") } }
3 Respuestas
+ 1
You can use an array to store multiple strings!
For example:
var wordArr = ["foo", "bar", "spam", "eggs"];
PS:
klisco1, Use a for loop to check with every word.
for(let i in wordArr) {
if(wordArr[i] == o) {
// o is the value of the input in your case!
alert("You can't use such word!");
}
} // this code needs ES6 support!
Post PS:
klisco1, here it works for me:
v
https://code.sololearn.com/WxUxUb8UlucG/?ref=app
0
And what do I do next ?
0
Still doesn’t work