I'll paypal $5 to the first person who posts clean, working javascript that works in all major browsers and does the following: Background I already have some code that takes inputs from people on an html page as follows. function getTotal() { var v1 = parseInt(document.getElementById("txt1").value) var v2 = parseInt(document.getElementById("txt2").value) var v3 = parseInt(document.getElementById("txt3").value) var v4 = parseInt(document.getElementById("txt4").value) var v5 = parseInt(document.getElementById("txt5").value) and then we do: var stp = 0 if (isNaN(v1)) { stp = 1 document.getElementById("txt1").value = ""; document.getElementById("txt1").focus() alert("Not a valid entry!") return } etc, etc,etc. So I get five numbers which are then added: var total = v1+v2+v3+v4+v5; document.getElementById("total").value = total; The Job Please modify the script so that, instead of printing the total, it prints phrases on the html page depending on what the total is - IF the total is less than 5, output “you like butter†on the page If the total is more than or equal to 5 and less than 10, output “you like cheese†If the total is more than or equal to 10 and less than 15, output “you like milk†If the total is more than or equal to 15 and less than 29, output “you like yogurt†If the total is more than or equal to 20 and less than 25, output “you like custard†If the total is more or equal to 25 and less than 30, output “you like creamâ€
Didn't test it, but you could try this: var total = v1+v2+v3+v4+v5; var str = ""; if (total < 5) { str = "you like butter"; } else if ((total >=5)&&(total <10)) { str = "you like cheese"; } else if ((total >=10)&&(total <15)) { str = "you like milk"; } else if ((total >=15)&&(total <20)) { str = "you like yogurt"; } else if ((total >=20)&&(total <25)) { str = "you like custard"; } else if ((total >=25)&&(total <30)) { str = "you like cream"; } document.getElementById("total").value = str; Code (markup):
You're wellcome and keep the money, just give me some rep for the answer, that's all The code could eventually be further optimized, something along these lines should work fine too: if (total < 5) { str = "you like butter"; } else if (total <10) { str = "you like cheese"; } else if (total <15) { str = "you like milk"; } ... etc ... Code (markup):