Need help urgently!

Hi, can someone help me? The prompts are not displaying…

function petDetails() {
    var arrPet = [];

    var vType = "";
    vType = prompt("Enter pet type.");
    if (vType.length > 0) {
        arrPet.push(vType);
    }

    var vName = "";
    vName = prompt("Enter pet name"); 
    if (vName.length > 0) {
        arrPet.push(vName);
    }

    var vAge = "";
    vAge = prompt("Enter pet age.");
    if (vAge.length > 0) {
        arrPet.push(vAge);
    }
}

function listDetails(arrPet) {
	var vOut = "";
    if (arrPet.length == 0) {
        document.getElementById("output").innerHTML= "There is nothing to display.";
    } else {
        for (let i = 0; i < arrPet.length; i++) {
            vOut += (i + 1) + '. ' + arrPet[i].vType + " " + arrPet[i].vName + " " + arrPet[i].vAge +'</br>';
        }
        document.getElementById("output").innerHTML= "List of pets: " + vOut + "<br />";
    }
}

function calcAge(arrPet) {
    var vTotal = 0;
    for (let i = 0; i < arrPet.length; i++) {
    vTotal += arrPet[i].vAge;
    var vAvg = vTotal/(arrPet.vAge).length;
    document.getElementById("calc").innerHTML= "Average age of pets: " + vAvg + "<br />";
    }
}

function sort() {

}

function init() {
  //output
}

window.onload = init;

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

2 Likes

Hi @vanchu !

Welcome to the forum!

Where are you calling the petDetails function?
I don’t see that in your code.

If you want those three prompts to work then you need to call the function they are in.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.