Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
694596b0585c11170ac7c7fa Challenge 162: Energy Consumption 28 challenge-162

--description--

Given the number of Calories burned during a workout, and the number of watt-hours used by your electronic devices during that workout, determine which one used more energy.

To compare them, convert both values to joules using the following conversions:

  • 1 Calorie equals 4184 joules.
  • 1 watt-hour equals 3600 joules.

Return:

  • "Workout" if the workout used more energy.
  • "Devices" if the device used more energy.
  • "Equal" if both used the same amount of energy.

--hints--

compareEnergy(250, 50) should return "Workout".

assert.equal(compareEnergy(250, 50), "Workout");

compareEnergy(100, 200) should return "Devices".

assert.equal(compareEnergy(100, 200), "Devices");

compareEnergy(450, 523) should return "Equal".

assert.equal(compareEnergy(450, 523), "Equal");

compareEnergy(300, 75) should return "Workout".

assert.equal(compareEnergy(300, 75), "Workout");

compareEnergy(200, 250) should return "Devices".

assert.equal(compareEnergy(200, 250), "Devices");

compareEnergy(900, 1046) should return "Equal".

assert.equal(compareEnergy(900, 1046), "Equal");

--seed--

--seed-contents--

function compareEnergy(caloriesBurned, wattHoursUsed) {

  return caloriesBurned;
}

--solutions--

function compareEnergy(caloriesBurned, wattHoursUsed) {
  const workoutEnergy = caloriesBurned * 4184;
  const deviceEnergy = wattHoursUsed * 3600;

  console.log(workoutEnergy);
  console.log(deviceEnergy);
  if (workoutEnergy > deviceEnergy) return "Workout";
  if (deviceEnergy > workoutEnergy) return "Devices";
  return "Equal";
}