impactbyte-haku / projects

🌐 Projects
https://gitlab.com/impactbyte/learn/course-fullstackweb
9 stars 1 forks source link

Project JavaScript Loops #18

Open mhaidarhanif opened 5 years ago

mhaidarhanif commented 5 years ago

Submit here.

sarahgushef commented 5 years ago

https://github.com/sarahgushef/project-javascript-loops

rizariza69 commented 5 years ago

https://github.com/rizariza69/project-javascript-loops

dickymr commented 5 years ago

https://github.com/dickymr/project-javascript-loops

nchristanto commented 5 years ago

https://github.com/nchristanto/project-javascript-loops

arifinoid commented 5 years ago

https://github.com/arifinoid/project-javascript-loops

codedarlyn commented 5 years ago

https://github.com/codedarlyn/project-javascript-loops

zeinhm commented 5 years ago

https://github.com/Zaynhmad/project-javascript-loops

yfrance commented 5 years ago

https://github.com/yfrance/project-javascript-loops

mhaidarhanif commented 5 years ago
const dailySteps = [
  {
    day: 1,
    totalSteps: 1900
  },
  {
    day: 2,
    totalSteps: 2200,
    favorite: true
  },
  {
    day: 4,
    totalSteps: 1200
  },
  {
    day: 5,
    totalSteps: 2400,
    favorite: true
  }
]

for (let index = 0; index < dailySteps.length; index++) {
  const stepData = dailySteps[index]

  if (stepData.favorite === true) {
    console.log(`[Day ${stepData.day}] ${stepData.totalSteps} steps ⭐`)
  } else {
    console.log(`[Day ${stepData.day}] ${stepData.totalSteps} steps`)
  }
}
mhaidarhanif commented 5 years ago
const myDailySteps = [
  {
    day: 1,
    steps: 1900
  },
  {
    day: 2,
    steps: 2200
  },
  {
    day: 3,
    steps: 900
  },
  {
    day: 4,
    steps: 1200
  },
  {
    day: 5,
    steps: 2400,
    favorite: true
  }
]

// -----------------------------------------------------------------------------

const showDailyStepsData = data => {
  for (let index = 0; index < data.length; index++) {
    const item = data[index]

    if (item.favorite === true) {
      console.log(`[Day ${item.day}] ${item.steps} steps ⭐`)
    } else {
      console.log(`[Day ${item.day}] ${item.steps} steps`)
    }
  }
}

// -----------------------------------------------------------------------------

const filterMostActiveDays = (data, minimumSteps) => {
  let newDailySteps = []

  for (let index = 0; index < data.length; index++) {
    const item = data[index]

    if (item.steps > minimumSteps) {
      newDailySteps.push(item)
    }
  }

  return newDailySteps
}

// -----------------------------------------------------------------------------

const minimumStepsInput = prompt(
  'What is your target of minimum steps per day?'
)

const filteredData = filterMostActiveDays(myDailySteps, minimumStepsInput)

// -----------------------------------------------------------------------------

console.log('Show all data:')
showDailyStepsData(myDailySteps)

console.log('')

console.log('Show only filtered data:')
showDailyStepsData(filteredData)
mhaidarhanif commented 5 years ago

https://gist.github.com/mhaidarh/3a71329c3c8f467d6003fe06e6d56993

yevgenysiregar commented 5 years ago

https://github.com/yevgenysiregar/project-javascript-loops