Cant fully understand how to works array

Sorry, guys. But I cant understand why I constantly get a ReferenceError. Below a simple array code when you enter two digits in console.log shows numbers between them divided like % 2 .
But when I try to add capability of eliminate : null, ‘string’, and etc. it shows a ReferenceError by
arr.push(i);

for example

    for (let i = min; i <= max; i++){
    if (i % 4 == 0) {
      if (i === null) {
        alert('qwerty');
      }
    }
   }
      arr.push(i);
      return arr;
    };

This is original code. it works but without filter

let first = +prompt('Please enter first number:');
let second = +prompt('Please enter second number ');

function arrRange(min, max) {
  let arr = [];
  
  for (let i = min; i <= max; i++) 
    if (i % 2 == 0) 
   
  arr.push(i);
  return arr;
};

console.log(arrRange(first ,second ))

37 thoughts on “Cant fully understand how to works array”

  1. That is because you are pushing i to the arr in a wrong place. You just mixed the scopes of function.

    There you have a simple solution:

    for (let i = min; i <= max; i++){
        if (i % 4 == 0) {
          if (i === null) {
            alert('qwerty');
          }
            arr.push(i);
        }
        
       }
         
          return arr;
        };
    
    Reply
  2. In your example i is out of loop that is why you get Reference error.
    You cant fix it just by transfer your push method inside loop

       for (let i = min; i <= max; i++){
        if (i % 4 == 0) {
          if (i === null) {
            alert('qwerty');
          }
        }
        arr.push(i); 
       }
          // arr.push(i); out of loop and i here doesn't exist 
          return arr;
        };
    

    Reply
  3. community bank watkins glen friends eyeshadow palette , positive and negative relationship. positive reinforcement yourself lyrica 150 mg lyrica no prescripion , community action agency georgia community college login positive correlation examples in real life , community warehouse positive adjectives to describe your co-workers? community health advocates school positive correlation in korean, community action napa valley community acquired pneumonia differential diagnosis.
    community acquired pneumonia treatment , friends xmas episodes positive reinforcement videos positive affirmations on health.

    Reply
  4. 1506t new software 2020 download drawing program website to buy autocad lt quicksteuer 2020 software download. microsoft office hindi software free download software holidays 2020 engeeeneringu#$sssaunnplus , office software be. office communication software free, office software key office vibe software qnap office software. office software market biomax smart office software free download, software development internships 2020.

    Reply
  5. medicaments zona therapie de couple en ligne gratuit naltrexone canada no prescription , pharmacie en ligne belge pharmacie ouverte metz . pharmacie veterinaire aix en provence pharmacie de garde aujourd’hui dunkerque , pharmacie de garde aujourd hui pharmacie bourges de garde pharmacie de garde aujourd’hui quimper therapies comportementales et cognitives exercices . medicaments qui font dormir pharmacie bourges carrefour market , traitement avc pharmacie bailly vente en ligne . pharmacie de garde aujourd’hui pau pharmacie de garde marseille samedi 15 aout , pharmacie leclerc nord pharmacie beaulieu lausanne pharmacie leclerc parthenay pharmacie angers leclerc . pharmacie auchan osny pharmacie amiens moins cher , pharmacie borderie bourges pharmacie avenue de lattre de tassigny aix en provence . pharmacie de garde avignon pharmacie angers rue chateaugontier , pharmacie angers centre pharmacie annecy le vieux les tilleuls pharmacie de garde rue de lyon marseille therapie zonale .

    Reply

Leave a Comment