-1

so i have this object in javascript:

const systolicAndDiastolicAndPulseAverage = [
    {
      name:'Systolic Average',
      style:'#FFDA83',
      id:'right',
      category:'Systolic Average',
      data: [
        { day: 23, value: 100 },
        { day: 24, value: 110 },
        { day: 25, value: 115 },
        { day: 26, value: 112 },
        { day: 27, value: 108 },
        { day: 28, value: 95 },
        { day: 29, value: 99 },
        { day: 30, value: 89 },
        { day: 31, value: 124 },
      ]
    },
    {
      name:'Diastolic Average',
      style:'#EA1D75',
      id:'left',
      category:'Diastolic Average',
      data: [
        { day: 23, value: 61 },
        { day: 24, value: 65 },
        { day: 25, value: 82 },
        { day: 26, value: 74 },
        { day: 27, value: 69 },
        { day: 28, value: 59 },
        { day: 29, value: 67 },
        { day: 30, value: 71 },
        { day: 31, value: 74 },
      ]
    },
    {
      name:'Pulse Average',
      style:'#5FE3A1',
      category:'Pulse Average',
      data: [
        { day: 23, value: 80 },
        { day: 24, value: 83 },
        { day: 25, value: 65 },
        { day: 26, value: 72 },
        { day: 27, value: 79 },
        { day: 28, value: 93 },
        { day: 29, value: 96 },
        { day: 30, value: 91 },
        { day: 31, value: 46 },
      ]
    }
  ]

so basically what i am trying to do is iterate over each array inside( there are 3 arrays) and each time i will iterate inside and check if the value is between two ends and if its true i will add 1 to the counter.(ex i will first go inside systolic average and the data array inside, iterate on all the values and check them)

for(let i in systolicAndDiastolicAndPulseAverage){
            let dataParsed = systolicAndDiastolicAndPulseAverage[i].data;

            for(let j=0;j<=dataParsed.length;j++)
            {

                let currentValue = dataParsed[j].value
                if(currentValue.value <= 89){
                    lowerEnd++;
                }
                if(currentValue.value>=90 && currentValue.value <= 119){
                    lowMed++;
                }
                if(currentValue.value >= 120 && currentValue <=139){
                    highMed++;
                }
                else{
                    high++
                }
            }
        }

        console.log(lowerEnd)
        console.log(lowMed)
        console.log(highMed)
        console.log(high)

this is my code so far and its giving me this error why whats the problem i checked the logic using console.log without the loop and its working so why its not working with the loop please help

M.I
  • 379
  • 3
  • 18

1 Answers1

0
for(let i in systolicAndDiastolicAndPulseAverage){
  let dataParsed = systolicAndDiastolicAndPulseAverage[i].data;

// 1. not <= cose [9] object.value , just <

for(let j=0;j <  dataParsed.length;j++)
  {

// 2. let currentValue = dataParsed[j] .value is false try without .value

     let currentValue = dataParsed[j]
      if(currentValue.value <= 89){
          lowerEnd++;
      }
      if(currentValue.value>=90 && currentValue.value <= 119){
          lowMed++;
      }
      if(currentValue.value >= 120 && currentValue <=139){
          highMed++;
      }
      else{
          high++
      }
  }
}
  • What have you changed? And why? [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting) – Andreas Jun 16 '20 at 13:31