+ 4
My first serious project on playground 😎
I just want to thank @Maz for your help about flag icons :) Look at this, and if you like it, press like xD And comment if you have some suggestion and new countries to update :) https://code.sololearn.com/W9cAVh51EPO0/?ref=app
3 odpowiedzi
+ 8
Good stuff for a begin ;)
I suggest you to improve your code by storing separatly country names and class names for flag, and update them separatly:
<div class="country" id="country"><span></span><span></span></div>
var country = [
{ name: "Serbia - Belgrade", class: "flag-icon flag-icon-rs" },
{ name: "Russia - Moscow", class: "flag-icon flag-icon-ru" },
{ name: "Poland - Warsaw", class: "flag-icon flag-icon-pl" },
];
function con() {
div = document.querySelector("#country span:first-child");
span = document.querySelector("#country span:last-child");
setInterval(function(){
var random = Math.floor(Math.random()*country.length);
div.innerHTML = country[random].name+' ';
span.className = country[random].class;
}, 2000);
};
( ... and use length property of your country array to calculate random index ^^ )
+ 3
@visph yeaa xD sure man, when I catch time, I will try to improve my code, I am at begining with js :)
+ 1
whoah!