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

104
Vistas
TypeError in JavaScript when setting the Y position

When running this code I currently getting the error "TypeError: Invalid value for y-coordinate. Make sure you are passing finite numbers to setPosition(x, y)." all of my functions do work are are declared properly. When I use a println and print out letYPos it prints out "NaN" but when I call the function again it prints out the correct value. Does anyone know how I can fix this or if there even is a way to fix this?

var count   = 0;
var letYPos = 0;
var y       = 3;

function testing()
  {
  var letXPos = 25;
  letYPos    += 75;
  if (count == 6) 
    {
    println("You have ran out of guesses, the correct anwser was: " + secretWord);
    return;
    }
  var input = readLine("Enter your word: ");
  if (input == null) 
    {
    println("You have to enter a word! ");
    return;
    }
  if (input.length != 5)
    {
    println("That is not a five letter word, please try again.");
    return;
    }
  var x = 3;
  for (var i = 0; i < input.length; i++) 
    {
    if (input.includes(secretWord.charAt(i))) 
      {
      var index = input.indexOf(secretWord.charAt(i));
      }
    if (index == 0) { yellow(3, y  ) }
    if (index == 1) { yellow(83, y ) }
    if (index == 2) { yellow(163, y) }
    if (index == 3) { yellow(243, y) }
    if (index == 4) { yellow(323, y) }    index = null;
    }
  for (var i = 0; i < input.length; i++) 
    {
    if (input.charAt(i) == secretWord.charAt(i))
      {
      green(x, y);
      }
    x += 80;
    }
  y += 80;
  for (var i = 0; i < input.length; i++) 
    {
    for (var a = 0; a <= 5; a++) 
      {
      var txt = new Text(input.charAt(a), font);
      txt.setPosition(letXPos, letYPos);
      add(txt);
      letXPos += 80;
      }
    }
  if (input == secretWord) 
    {
    println("That's Correct, Congratulations!");
    return;
    }
  count++;
  setTimeout(testing, 100);
  }
about 4 years ago · Juan Pablo Isaza
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