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

Q: Multiply a Number by X

+12 votes

You are given a number N and a number X. Create a program that multiplies N * X and prints the result.

Examples:

Input

Output

 

Input

Output

 

Input

Output

 

Input

Output

2

3

6

 

13

13

169

1

2

2

0

50

0

 

asked in JavaScript category by user golearnweb

2 Answers

+2 votes
 
Best answer

Here's the function:

function multiply(args) {
  let n = parseInt(args[0])
  let m = parseInt(args[1])
  console.log(n * m)
}

 

answered by user hues
selected by user golearnweb
+3 votes

Here is the code with html form:

<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8/>
  <title>JavaScript program</title>
  <style type="text/css">
    body {
      margin: 30px;
    }
  </style>
</head>
<body>

<form>
  <div>1st Number:</div>
  <div><input type="number" id="num1"/></div>
  <div>2nd Number:</div>
  <div><input type="number" id="num2"/></div>
  <div><input type="button" value="Calc Sum" onclick="sumNumbers()"/></div>
  <div>Result: <span id="result"></span></div>
</form>

<script>
  function sumNumbers() {
    let num1 = document.getElementById('num1').value;
    let num2 = document.getElementById('num2').value
    let sum = num1 * num2
    document.getElementById('result').innerHTML = sum;
  }
</script>

</body>
</html>

 

answered by user eiorgert
...