here is my code.
<SCRIPT LANGUAGE=JavaScript>
function main()
{
var name;
var pet;
var postcode;
var price;
var finalprice;
var card;
postcode = 0;
//asks the user there name.
name = prompt("Hello What is your name?","");
//asks them what pet they want
pet = prompt(""+name+" would you like to buy a cat or a dog?","");
if (pet == "cat") {
alert("Cats Cost $10");
}
else if (pet =="dog") {
alert("Dogs Cost $20");
}
else {
alert("sorry please enter cat or dog.");
}
//asks them for there postcode.
postcode = prompt(""+name+" what is your postcode?","");
if(postcode.length !=4) {
alert("Please enter a postcode of 4 digits");
}
//shows them what they have to pay
card = prompt(""+name+" will you be paying with card or cash?","");
if(card == "card") {
alert("You selected card if you pay cash you get a 10% discount");
}
else if (card == "cash") {
alert("You are paying cash you get a 10% discount")
}
else {
alert("please enter card or cash");
}
//price of pet
if (pet == "cat") {
price = 10;
}
else if (pet == "dog") {
price = 20;
}
//final price
if (card == "cash") {
finalprice=price*0.9;
}
else if (card == "card") {
finalprice=price*1
}
//the text dispallyed
document.write("Thankyou "+name+" for purchasing a "+pet+"");
document.write(" you are paying with "+card+" the final price is $"+finalprice+"")
document.write(" your Post Code is "+postcode+"")
}
</script>
i need a way to make the things like postcode and that not let them go through with out being 4 digits. any help really apperciated <3
thanks guys :)


Sign In
Create Account

Back to top









