Answer the question
In order to leave comments, you need to log in
How to determine if a city is entered or not?
I am writing a game in html/css/js in Cities. Faced a problem: how to determine whether a city is entered or not? Maybe there is some API or library, or can I check with an HTTP request?
Answer the question
In order to leave comments, you need to log in
The easiest
<input style="text-transform: uppercase;">
<button onclick="city();">Добавить</button>
<script>
var inCity = document.body.children[0];
var arrCity = [];
function city(){
var yn = arrCity.indexOf(inCity.value);
if(yn >= 0){
alert('Такой город был' );
}else{
arrCity.push(inCity.value);
alert('Такого города еще небыло');
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question