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

129
Views
Not imputing items into my array properly
var list = ""
var items = [];
var item=[];
var counter = 1;
var savedCount= 0;
var useSaved=false;
var bbPos = []
var used =[]
var needed=25;
var used=false;
var rnum=Math.floor(Math.random()*needed);
var done =false
var counterR = 0;
var round1=true;
var usedNum = false;

function freeSpace(){
  if(items[25]!=null){
    alert("you have to many items for a free space")
  }
  else{
    needed=24
 if(document.getElementById("freeSpacer").value == "yes"){ 
   document.getElementById("freeSpacer").value = "no"
   bbPos[13] = "Free Space!"
 }
  else{
    document.getElementById("freeSpacer").value = "yes"
}
  
}
}
function enter(){
  if(counter<=needed){
    if(useSaved==true){
      items[counter] =  document.getElementById("items").value;
  document.getElementById("items").value = ""; 
  document.getElementById("item"+counter).innerHTML =  counter + ". " +items[counter];
  counter=savedCount;
    }
    else{
  items[counter] = 
  document.getElementById("items").value;
  document.getElementById("items").value = ""; 
  document.getElementById("item"+counter).innerHTML =  counter + ". " +items[counter];
  counter+=1;
    }
  }
  else{
    document.getElementById("output").innerHTML="You are out of room for your bingo board";
  }
}

function start(){

  if(items[needed]!=null){
    counter =1;
    for(i=0;i<=needed;i++){
      checker1();
      document.getElementById("box"+counter).innerHTML= used[i];
      counter+=1;
    }
   
  }
  else{
    alert("you do not have enough items to fill your board");
  }
}
function checker1(){
  needed-=1;
  rnum=Math.floor(Math.random()*needed);
  needed+=1;
  for(i=0;i<needed;i++){
    if(rnum==used[i]){
      usedNum=true;
    }
    else{
      usedNum=false;
    }
  }
  if(usedNum==true){
    checker1();
  }
  else if(usedNum==false){
   used[counterR]=rnum;
   counterR+=1;
  }
  
  
}

Bassicaly I think my issue lies in the checker function. Whats supposed to happen is a for loop runs checker however many times it needs (25 or 24) to set that many random numbers into an array and check if that number has been used. Instead what happens is only the 0 posistion is set to undefined and im extremely confused why. Pardon my exsessive variable usage and crappy code. If anyone knows why this is happening it would be appreciated

about 4 years ago · Juan Pablo Isaza
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!