settingsAccountsettings
Menusettings

Q: Multiply a Number by 2

+14 votes

You are given a number N. Create a program that multiplies that number by 2 and prints the result.

Examples:

Input

Output

2

4

Input

Output

3

6

Input

Output

30

60

Input

Output

13

26

 

asked in JavaScript category by user ak47seo

2 Answers

+3 votes
 
Best answer

Here is the answer:

Note: you must first install Node.js source code or a pre-built installer for your platform from HERE: https://nodejs.org/en/download/ so WebStorm can run in the console!

"use strict"
function sum(args) {
  let n = parseInt(args[0])
  console.log(n * 2)
}

 

answered by user andrew
edited by user golearnweb
+2 votes

Here it is with html form:

<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8/>
  <title>JavaScript program to calculate multiplication and division of two numbers </title>
  <style type="text/css">
    body {
      margin: 30px;
    }
  </style>
</head>
<body>

<form>
  <div>Number:</div>
  <div><input type="number" id="num1"/></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 sum = Number(num1) * parseInt("2");
    document.getElementById('result').innerHTML = sum;
  }
</script>

</body>
</html>

 

answered by user eiorgert
...