Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function operators(input)
- {
- let N1 = Number(input.shift());
- let N2 = Number(input.shift());
- let nOperator = input.shift();
- let result = 0;
- let output = ``;
- if ( N2 == 0 && (nOperator === '/' || nOperator === '%'))
- {
- output = `Cannot divide ${N1} by zero`;
- }
- else if ( nOperator === '/')
- {
- result = N1 / N2;
- output = `${N1} ${nOperator} ${N2} = ${result}`;
- }
- else if (nOperator === '%')
- {
- result = N1 % N2;
- output = `${N1} ${nOperator} ${N2} = ${result}`;
- }
- else
- {
- if (nOperator === '+')
- {
- result = N1 + N2;
- }
- else if (nOperator ==='-')
- {
- result = N1 - N2;
- }
- else if (nOperator === '*')
- {
- result = N1 * N2;
- }
- let numberIs = '';
- if ( result % 2 == 0)
- {
- numberIs = 'even';
- }
- else
- {
- numberIs ='odd';
- }
- output = `${N1} ${nOperator} ${N2} = ${result} - ${numberIs}`;
- }
- console.log( output );
- }
Add Comment
Please, Sign In to add comment