How do you calculate a string? | Sololearn: Learn to code for FREE!

+1

How do you calculate a string?

For example: Var equation = "30+54"; Var answer = equation; Equation = 30+54 Answer = 84

9/21/2022 9:00:58 AM

Laurence Ian

12 Answers

New Answer

+5

console.log(+"30"+(+"54")) //😉

+6

https://www.w3schools.com/jsref/jsref_parseint.asp

+5

you can use eval function 😁

+3

Console.ReadLine() by itself wont work, as you need the value to be an integer. This is where our old friend Convert.ToInt32 comes in. This allows us to take the integer values out of the input and use it as a variable. var Q = Console.ReadLine(Convert.ToInt32); Console.WriteLine(Q);

+3

You can also use: console.log(Number("5")+Number("5"))

+2

NinjaGamer64, initially the question was: "30"+"54" 🤔 But in this case: "30+54" - of course eval()

+1

parseInt con tema de funciones. Ahí está la respuesta

+1

from your needs I suppose you need to try the eval() function... A sample Javascript code is given below var num1 = "123 + 456"; var sum = eval(num1); console.log(sum) Terminal: ____________________________________ 579

0

Use eval.

0

var equation = "30+54" var answer = eval(equation); console.log(answer);

0

Hello, I have question If i am increase the numbers of string then it work automatacally? https://www.prepaidgiftbalance.biz/

0

Reenasky it should automatically increment the numbers