settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Multiply / Divide a Number by a given second number

+10 votes

You are given a number N and a number X. Create a program that multiplies N * X if X is greater than or equal to N and divides N / X if N is greater than X.

Examples:

Input

Output

 

Input

Output

 

Input

Output

 

Input

Output

2

3

6

 

13

13

169

3

2

1.5

144

12

12

 

asked in JavaScript category by user john7

1 Answer

+1 vote
 
Best answer

Here's my solution:

function calculateNumbers(args) {
  let n = parseInt(args[0]);
  let m = parseInt(args[1]);

  if (m >= n) {
    console.log(n * m);
  } else {
    console.log(n / m);
  }
}

 

answered by user Jolie Ann
selected by user golearnweb
...