CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2018-02-09
by drdoom59

Original Post

Original - Posted on 2018-02-08
by ꜱᴜʀᴇꜱʜ ᴀᴛᴛᴀ



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Solution:
let music = 'on'; let phone = 'on'; if (music === 'off' || phone === 'off'){ console.log('Music or phone is off'); } else if (music === 'on' && phone === 'on') { console.log('music is playing'); } else if (music === 'off') { console.log('music is off'); } else if (phone === 'off') { console.log('phone is off');enter code here } else if (music === 'off' && phone === 'off') { console.log('Both Phone and Music if off'); } else { console.log('Dont know why music is not playing'); }
You want to use `if-else-if` not `if-else`.
let music = 'on'; let phone = 'on'; if (music === 'off' || phone === 'off'){ console.log('Music or phone is off'); } else if (music === 'on' && phone === 'on') { console.log('music is playing'); } else if (music === 'off') { console.log('music is off'); } else if (phone === 'off') { console.log('phone is off');enter code here } else if (music === 'off' && phone === 'off') { console.log('Both Phone and Music if off'); } else { console.log('Dont know why music is not playing'); }
So now it only executes if none of the if's execute.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

        
Present in both answers; Present only in the new answer; Present only in the old answer;