I'm writing a bit code code that will calculate a price for a personalised product based on user input. In this case they have the option of choosing a message ("happy birthday" or "happy anniversary" or something similar) to appear in the finished product.
The price should be calculated based on the number of characters in the message. So the price should increase by £4 for every character, but should only increase by £2 for every blank space.
I having problems getting my code to go through each character in order to determine how much it should be charging. Any ideas where I'm going wrong?
this might help if my explanation isn't clear enough. http://jsfiddle.net/6QhAz/1/
code:
$(document).ready(function () {
jQuery("#phrase").keyup(function () {
var length = this.value.length;
var price;
var message =jQuery("#phrase").val;
for ( var i=0; i > length; i++) {
if (this.value === " " ) {
price + 1.50;
} else {
price + 2.50;
};
};
jQuery("#price").html('Price: £'+price);
});
});