var areYouReady = prompt("Are you prepared for this task?").toLowerCase();
var starting_DescriptionStart;
var starting_DescriptorOfThing;
var starting_Thing;
var starting_DescriptionEnd;
if(areYouReady === "begin"){
//Start the process
starting_DescriptionStart = ["You encounter a"];
starting_DescriptorOfThing = ["Huge", "Tiny", "Red", "Blue", "Green", "Black", "White", "Invisible", "Camo", "Striped", "Breathing", "Living", "Sentient"];
starting_Thing = ["Box", "Dragon", "Lion", "Eagle", "Tiger", "Vampire", "Dagger", "Bracelet", "Ring", "Tiara", "Stack of books", "Fox", "Cat", "King", "Witch", "Elf", "Magician", "Table", "Mustard"];
starting_DescriptionEnd = ["that is trying to harm you.", "at the beach.", "on social media.", "in a haunted house.", "at a carnival.", "below ground.", "high up in a tree.", "at a fancy party.", "outside."];
// Generate random numbers
var randomNumber1 = parseInt(Math.random() * starting_DescriptionStart.length);
var randomNumber2 = parseInt(Math.random() * starting_DescriptorOfThing.length);
var randomNumber3 = parseInt(Math.random() * starting_Thing.length);
var randomNumber4 = parseInt(Math.random() * starting_DescriptionEnd.length);
generatedSituation = starting_DescriptionStart[randomNumber1] + " " + starting_DescriptorOfThing[randomNumber2] + " " + starting_Thing[randomNumber3] + " " + starting_DescriptionEnd[randomNumber4];
alert(generatedSituation);
}else if(areYouReady === "add description start"){
//Allow user to add a new descriptor
var s_DescStart = starting_DescriptionStart.length + 1;
var inputA = prompt("What do you want to incorporate into the introductory description?");
starting_DescriptionStart[s_DescStart] = inputA;
alert(starting_DescriptionStart[1]);
}
I am working with this piece of code, which can be easily expanded by adding elements to the arrays. However, I am looking to create a system where users can contribute to it and then execute the updated version.
After attempting to add new descriptions and encountering an error message when running the program:
Uncaught TypeError: Cannot read property 'length' of undefined
I'm puzzled as to why it's indicating that the variable is undefined, considering it should be globally accessible.