0

I created a string let clientName = ""

Then I have an input question clientName = input.question ("What is your name? ")

The answer to the input question will change. How do I get the answer to fill the empty string?

1
  • Declare your variable at global scope. Then when you get the answer back from the user, you can reassign the value to it. Or you could assign it to the window object. window.clientName = 'new value'. Or you could use localstorage or a document.cookie Commented Jun 18, 2021 at 22:48

3 Answers 3

1

Do you mean prompt()?

let clientName = prompt("What is your name?");
console.log(clientName)

Sign up to request clarification or add additional context in comments.

2 Comments

This is what I did and now it works - I think let contactName= input.question.contactName contactName = input.question ("What is your name? ") console.log (Contact Name: ${contactName})
I don't see prompt() in there - it doesn't make sense to me unfortunately. Did you want the popup to ask the question or just have an input element (text box) where someone types it in?
0
  <html>

<div>What is your name?</div>
  <input type="text" id="name" onchange="getName()" name="name" value="">

<script>

function getName() {

let clientName = "";
clientName= document.getElementById("name").value;
console.log(clientName);
}

</script>

</html>

Comments

0

you should simply assign the new value like this:

clientName = //the new value you want assign to the client name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.