Reputation: 582
I have this piece of code:
use_result = window.confirm("You have 1 registration credits. Do you wish to use a registration credit for this player?");
The digit 1
there is not dynamic, it is manually assigned. What I want is that I will have a variable placed instead of the digit 1
, such that it's value is dynamic. Would that be possible? Thanks.
Upvotes: 0
Views: 2240
Reputation: 47956
You can simply replace that static value with a variable -
var numberOfRegistrations = 1;
use_result = window.confirm("You have "+ numberOfRegistrations +" registration credits. Do you wish to use a registration credit for this player?");
The final string that is displayed in the confirm dialog will be a concatenation of the surrounding strings and your predefined dynamic variable.
In the same way that when you add numeric values together you will get the sum of those values, with strings, using the +
operator will simple combine the two strings.
var firstWord = "Stack";
var secondWord = "Overflow";
alert(firstWord + seconfWord); // This will alert the string - "StackOverflow";
You can combine as many strings as you want together to create a final string -
alert('Hello' + ' ' + 'World'); // This will alert the string - "Hello World"
Note in the last example I am joining 3 strings.
Hello
World
Upvotes: 1
Reputation: 250
use string concatenation with the + operator.
var a = /*... */;
use_result = window.confirm("You have "+ a +" registration credits. Do you wish to use a registration credit for this player?");
Upvotes: 1
Reputation: 160181
Yes; the easiest would use string concatenation:
use_result = window.confirm("You have " + n + " registration credits. Do you wish to use a registration credit for this player?");
Upvotes: 4