My last JS question, i swear

ok, let’s say i have a variable called yourPets that is defined by a prompt.

 var yourPets= prompt('What pet's do you have?'); 

let’s say the user types “I have a dog” into the prompt box. yourPets now equals “I have a dog.”

now let’s say i want to make it so when yourPets displays, instead of “I” i want “You” to appear.

so if an alert box came up with the value (yourName) it would display “You have a dog” instead of “I have a dog.”

does that make sense? i hope so. sorry for all the questions, this is my last i swear.

You should base that script on keywords… such as names like… dog, cat, bird, none… not based off a statement. That way when you have your JS read over what was typed it see’s one of those keywords and then places it in a statement that you’ve already predetermined. Like if I said “A funky dog”… what would the response be to that?

yourPets = yourPets.split(“I”).join(“You”);


many many thanks :slight_smile:

to answer your question, this is how it would look:

var yourPets = prompt('What kind of pets do you have?');
yourPets = yourPets.split("I have").join(" ");

alert("You have " + yourPets + "?");

even still, that is a poor example, but i forgot what it was that i was doing where i needed to change “I” to “you”.

thats what the forums are here for, to help people who have questions…don’t feel guilty ask away :slight_smile: