0

I am a junior developer.. iam trying to typing a program that predicts the age of football players on the screen.. but the code does not work in a way I dont understand, what do you think the problem is? (iam typing 36 to the first image but it does not working)

var index = 0;
var images = document.getElementsByClassName("image");
var dots = document.getElementsByClassName("dot");

show_slide = (i) => {
  index += i;

  for (var j = 0; j < images.length; j++) {
    images[j].style.display = "none";
  }

  for (var k = 0; k < dots.length; k++) {
    dots[k].className = dots[k].className.replace(" active", "");
  }

  if (index > images.length - 1) {
    index = 0;
  }

  if (index < 0) {
    index = images.length - 1;
  }

  images[index].style.display = "block";
  dots[index].className += " active";
}

window.addEventListener("load", function() {
  show_slide(index);
});

function tahminEt() {
  var dogruYas;

  // İndekse göre doğru yaş değerini belirleyin
  if (index === 1) {
    dogruYas = 36; // Messi'nin yaşını buraya girin
  } else if (index === 2) {
    dogruYas = 32;
  } else if (index === 3) {
    dogruYas = 38;
  } else if (index === 4) {
    dogruYas = 31;
  } else if (index === 5) {
    dogruYas = 36;
  } else {
    document.getElementById('sonuc').textContent = "Maalesef yanlış tahmin ettiniz.";
    return; // Doğru yaş değeri tanımlı değilse, fonksiyondan çık
  }

  var tahmin = parseInt(document.getElementById('tahmin').value);

  if (isNaN(tahmin)) {
    document.getElementById('sonuc').textContent = "Lütfen geçerli bir sayı girin.";
  } else {
    if (tahmin === dogruYas) {
      document.getElementById('sonuc').textContent = "Tebrikler! Doğru tahmin ettiniz.";

      // Doğru tahmin yapıldığında bir sonraki fotoğrafa geç
      show_slide(1);
    } else {
      document.getElementById('sonuc').textContent = "Maalesef yanlış tahmin ettiniz.";
    }
  }
}

i do wanna what is the problem and how can i fix it

  • 1
    Welcome to Stack Overflow! This is a good opportunity for you to start familiarizing yourself with [using a debugger](https://stackoverflow.com/q/25385173/328193). When you step through the code in a debugger, which operation first produces an unexpected result? What were the values used in that operation? What was the result? What result was expected? Why? To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Jul 13 '23 at 12:23
  • Please edit your question and include the relevant HTML and CSS. – Scott Marcus Jul 13 '23 at 12:35
  • It's rather hard to follow code around that isn't in English. Hint: try to use English. The programming language is already in English anyway, so writing in your native language just makes the whole thing more confusing - at least in my experience (I tried it in Dutch once and regretted it almost instantly) – somethinghere Jul 13 '23 at 12:35

0 Answers0