Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!