Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
How do i display an array as a list that can expand columns/rows when it gets too big

I am making a project for school, its a basic country guessing game where you type in the name of a country in an input field and press enter to check if its correct or not.

The function below is supposed to check the input field to the country list array to see if its correct. Now i dont have a problem displaying it but i would like the array to be displayed more like a list and for it to make a new row/column if its about to go outside the edge of the box its being displayed in.

Visualization of array display problem

Preferably the array should start by filling 1 column then when it's about to hit the bottom of the box its displayed in it should start a new column and continue.

I have tried almost everything, even adding the input field value to a list without using an array but then i had a trouble checking if the input value was already guessed or not. obviously you shouldn't be able to write Spain 7 times.

Any help much appriciated.

js.

var guessedCorrect = [];

addEventListener("keyup", function(e) {
    if(e.keyCode === 13) {
        input = document.getElementById("input").value;
        if (countryList.indexOf(input) > -1 && guessedCorrect.indexOf(input) == -1) {
            guessedCorrect.push(input);
            document.getElementById("countryArray").innerHTML = guessedCorrect; 
        } 
        if (guessedCorrect.indexOf(input) > -1) {

        }
        document.getElementById("input").value = "";
    }
});

HTML

<body>
    <main>
        <div id="gameContainer"> 
            <button id="startGame" onclick="startGame()" >Start</button>
            <button id="resetGame" onclick="resetGame()" >Reset</button>
            <div id="inputArea">
                <input type="text" id="input" placeholder="Guess country.." name="input">
            </div>
            <div id="timerArea">
                
                <span id="timer"></span>
                
            </div>
            <div id="textArea">
                <div id="countryArray"></div>
            </div>
        </div>
    </main>

    <script src="../js/script.js"></script>
</body>

CSS

#countryArray {
    margin: 1rem 1rem;
}
#textArea {
    grid-column-start: 4;
    grid-column-end: 7;
    grid-row-start: 2;
    grid-row-end: 5;
    margin: 15px;
    Background-color: white;
    border-radius: 20px;
    border: 4px solid black;
    max-width: 100%;
    
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda