pls im having an issue with comparing the objects by the evilFactor field.
this is the code i tried:
export const getLesserEvil = (threat1, threat2) => { return Math.min(threat1.evilFactor, threat2.evilFactor); }
Start with using the if statement.
if
Then return the threat with the smallest evil factor.
It'll be like:
if (threat1.evilFactor < threat2.evilFactor) { // return something } else { // return something else }
I tried the below code but still not passing the task
export const getLesserEvil = (threat1, threat2) => { if (threat1.evilFactor < threat2.evilFactor) { return aiThreat; } else { return globalPandemic; } }
please what am i doing wrong
yes i got it below is the code
export const getLesserEvil = (threat1, threat2) => { if (threat1.evilFactor < threat2.evilFactor) { return threat1; } else { return threat2; } }
@highpee you nailed it!
The shortest code so far for me:
if (threat1.evilFactor > threat2.evilFactor) return threat2; else return threat1;
techbantu looks good!
This task makes no sense to me.
` export const getLesserEvil = (threat1, threat2) => {
if (threat1.evilFactor <= threat2.evilFactor) { //You shoudn't be able to know the 'evilFactor' from the superclass. return threat1; } else return threat2; } `
TioPew there's no superclass, you just analyze the value of the field evilFactor from the objects threat1 and threat2.
evilFactor
threat1
threat2
When I run the following code, it prints the correct outcome. However, I don't pass the task. What's wrong with it?
export const getLesserEvil = (threat1, threat2) => { if (threat1.evilFactor < threat2.evilFactor) return threat1.description; else return threat2.description; }
alorenz you should return the threat objects themselves, not their descriptions