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") } }

5th Apr 2018, 3:21 PM
klisco1
3 Answers
+ 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
5th Apr 2018, 3:31 PM
777
777 - avatar
0
And what do I do next ?
5th Apr 2018, 3:41 PM
klisco1
0
Still doesn’t work
5th Apr 2018, 4:00 PM
klisco1