Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
I'm making a wordle like game using Javascript and I can't find out how to test to see if the first letter of both comparable words are the same
var userWord = readLine("Enter a 5 letter word: \n");

var randomItem = listOfWords[Math.floor(Math.random()*listOfWords.length)];

var newWord = [userWord];

if(newWord != randomItem){
    letterChecker();
} else {
    println("Correct!");
}

Checks if the first letter of both words is the same or not, I can't seem to get how to find the first character of both arrays and compare. If I type in the correct word the "Correct!" prompt displays, however the "is green" doesn't appear.

function letterChecker(){

 if (newWord[0] === randomItem[0]{
        
        println(newWord[0] +" is green"); 
    } 

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't need to put newWord into array, use directly like:

var userWord = 'hi';
const listOfWords = ['hi', 'hello'];
var randomItem = listOfWords[Math.floor(Math.random() * listOfWords.length)];

var newWord = userWord;

if (newWord != randomItem) {
  letterChecker();
} else {
  console.log("Correct!");
}

function letterChecker() {
  console.log(newWord, randomItem);
  if (newWord[0] === randomItem[0]) {
    console.log(newWord[0] + " is green");
  }

}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda