M
M
mitra_mc2018-03-02 09:49:37
JavaScript
mitra_mc, 2018-03-02 09:49:37

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

1 answer(s)
O
Oleg, 2018-03-02
@politon

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 question

Ask a Question

731 491 924 answers to any question