-
[CODECADEMY] 코드카데미 CODE CHALLENGES: JAVASCRIPT FUNDAMENTALS 2Java Script 2020. 6. 17. 16:03
12. Fix the broken code (round 2)!
const whatRelation = percentSharedDNA => { if (percentSharedDNA === 100) { return 'You are likely identical twins.' } if (percentSharedDNA > 34 && percentSharedDNA < 100) { return 'You are likely parent and child or full siblings.' } if (percentSharedDNA > 13 && percentSharedDNA < 35) { return 'You are likely grandparent and grandchild, aunt/uncle and niece/nephew, or half siblings.' } if (percentSharedDNA > 5 && percentSharedDNA < 14) { return 'You are likely 1st cousins.' } if (percentSharedDNA > 2 && percentSharedDNA < 6) { return 'You are likely 2nd cousins.' } if (percentSharedDNA > 0 && percentSharedDNA < 3) { return 'You are likely 3rd cousins' } if (percentSharedDNA=== 0) {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.'
13. tipCalculator()
const tipCalculator=(quality ,total)=> { if (quality==='bad') { return total*0.05; } else if (quality==='ok') { return total*0.15; } else if (quality==='good') { return total*0.2; } else if (quality==='excellent') { return total*0.3; } else { return total*0.18; } } console.log(tipCalculator('good', 100)) // print20
14. toEmoticon(
const toEmoticon = (expression) => { switch (expression) { case 'shrug' : return '|_{"}_|'; case 'smiley face' : return ':)'; case 'frowny face' : return ':('; case 'winky face' : return ';)'; case 'heart' : return '<3'; default: return '|_(* ~ *)_|'; } } console.log(toEmoticon("winky face")) //print ;)
)
'Java Script' 카테고리의 다른 글