Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
var price11=100;
var i=11;
var displayprice;
displayprice= price+'i'; should assign 100(value of price11) to displayprice.

is it possible.?

What I have tried:

var price11=100;
var i=11;
var displayprice;
displayprice= price+'i'; should assign 100(value of price11) to displayprice.

is it possible.?
Posted
Updated 11-May-16 17:48pm

Why did you put single quotes around i? My guess is you copied code from somewhere. So, just take a deep breath and look at the code.

You are storing 100 in price11 and 11 in i. So, add them together, price + i.
 
Share this answer
 
Comments
Member 12517645 11-May-16 13:23pm    
no did not copied the code. i need to have displayprice with value of price11(dynamically). currently getting error. because price becomes a variable which is not defined.
ZurdoDev 11-May-16 13:31pm    
So, what exactly is your question then?
Member 12517645 11-May-16 13:37pm    
i have a price variables, price1=10, price2=20 and i=1. how do i assign price values to another variable.
var diplayprice;
displayprice = price+'i'; i is 1, so diplayprice should hold value of price1 which is 10
ZurdoDev 11-May-16 13:42pm    
You can use eval.

displayprice = eval("price" + i);
JavaScript
var price=100;
       var i=11;
       var displayprice;
       displayprice = price + 'i'; // this will result '100i', since the 'i' is considered as a string.
       displayprice = price + i; // this results 111, since both are of int type


In your case, you shall use eval[^], or Angular Js Expression[^] to get the value as int
JavaScript
displayprice = price + eval('i'); // 111
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900