Fix the broken code

I am having trouble with figuring out whats wrong with this code. I am looking at it for 30 min and I swear everything is the same as the solution xD. Does anyone know whats wrong? (https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-practice-javascript-syntax-variables-data-types-conditionals-functions/lessons/javascript-fundamentals-code-challenge/exercises/fix-the-broken-code-ii)

const whatRelation = percentSharedDNA => {

if (percentSharedDNA === 100) {

    return 'You are likely identical twins.'

}

if (percentSharedDNA > 34) {

    return 'You are likely parent and child or full siblings.'

}

if (percentSharedDNA < 13) {

    return 'You are likely grandparent and grandchild, aunt/uncle and niece/nephew, or half siblings.'

}

if (percentSharedDNA > 5) {

    return 'You are likely 1st cousins.'

}

if (percentSharedDNA > 2) {

    return 'You are likely 2nd cousins.'

}

if (percentSharedDNA > 0) {

    return 'You are likely 3rd cousins'

}

return 'You are likely not related.'

}

console.log(whatRelation(34))

// Should print ‘You are likely grandparent and grandchild, aunt/uncle and niece/nephew, or half siblings.’

console.log(whatRelation(3))

// Should print ‘You are likely 2nd cousins.’

Hey there,

I have moved your topic to the JavaScript section of the forums (was in Java).


console.log(whatRelation(34))

// Should print ‘You are likely grandparent and grandchild, aunt/uncle and niece/nephew, or half siblings.’

This cannot print if you test 34 against < 13, as 34 isn’t < 13.

Are you sure that this code is identical to the given solution?

1 Like

Yes. I think the code is the same I checked it over 30 times now. Maybe im just missing something not sure. Here is the solution code.

const whatRelation = percentSharedDNA => {

if (percentSharedDNA === 100) {

    return 'You are likely identical twins.'

}

if (percentSharedDNA > 34) {

    return 'You are likely parent and child or full siblings.'

}

if (percentSharedDNA > 13) {

    return 'You are likely grandparent and grandchild, aunt/uncle and niece/nephew, or half siblings.'

}

if (percentSharedDNA > 5) {

    return 'You are likely 1st cousins.'

}

if (percentSharedDNA > 2) {

    return 'You are likely 2nd cousins.'

}

if (percentSharedDNA > 0) {

    return 'You are likely 3rd cousins'

}

return 'You are likely not related.'

}

console.log(whatRelation(34))

console.log(whatRelation(3))

The devil is in the detail.

The solution code is slightly different to the code that you posted here.

Double check the line with the number 13 :wink:

lol, took me 10 mins even after you told me where to look, I would never spot that the less than is inverted.
Thank you very much for your time.

1 Like

My pleasure.

And don’t worry, you’ll get used to this with practice.
You’ll eventually be able to spot errors quickly, just keep at it.

1 Like