Ask coding questions

← Back to all posts
How do I write text on my website?
Hamburgr (18)

Currently, I am trying to try out making a website server to learn more about Javascript. I want to be able to prompt the user for questions and save them as variables. Many of the projects I have seen have custom made sprites that can have text. How do I make one of those. Here is my reference link: https://simple-live-chat.jser.repl.co/

Answered by Coder100 (17137) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (17137)

Try this for your html:

<input placeholder="Type in some text: " id="myInput">

And for your js:

let myVar = document.getElementById("myInput");
console.log(myVar);

and you see it did save to myVar.

Hamburgr (18)

@Coder100 Thank you for your answer! It helped me out a lot. However, I would also like to add things like a font so it doesn't look boring and maybe change the location and the border. By any chance, would you know how to do these? Also one more question, what did you mean by it saves to myVar (Like what saves? Is it the user input or username in my example? or is it something else?)?

~ Hamburger

Coder100 (17137)

in your css file:

input {
  border: none;
  border-bottom: 2px solid black;
}

just a teeny idea of what you could do
@Hamburgr

RYANTADIPARTHI (6011)

The way to do it in js, is by prompts:

var prompt_var = prompt("Prompt : ")

/* You can check what they are saying by using if statements*/

if (prompt == "HI") {
  console.log("Said hi")
}

in HTML:

<input type="text" placeholder="Type...">

That will just make a type box, where you can write.

RayhanADev (1967)

G’day @Hamburgr

The easiest way to create this with Javascript would be to either:

  • Use alerts:

Javascript

var prompt = prompt(‘What’s your name’);
  • or to use input fields (bit more complex):

HTML FILE

<input id=“myPrompt” placeholder=“Name”>

Javascript

var input = document.getElementById(‘myPrompt’).value

Hope this helps! Cheers,
~ Ray <3