Ask coding questions

← Back to all posts
how would you grab the username of the person running a JavaScript repl
Mathman05 (1)

If I made a new JS HTML and CSS project and in javascript, I wanted a variable called username that would contain the user's username if available and returns an empty string if unable, how would I call for the username?

Answered by TheForArkLD (763) [earned 5 cycles]
View Answer
Comments
hotnewtop
TheForArkLD (763)

Soo... wdym?
U want to save / read username?

Mathman05 (1)

@TheForArkLD like for me it would return "Mathman05 (0)" and for you it would return "TheForArkLD (748)" make sense? thanks for trying to help :D

TheForArkLD (763)

@Mathman05 o, then use localStorage.

var username = localStorage.getItem("username") || "";
TheForArkLD (763)

@Mathman05 yes, user must set username by localStorage.setItem("username",/*username*/) before do it

Mathman05 (1)

@TheForArkLD that's not what I'm trying to do. I'm trying to get their repl username. any idea how I would do that? sorry for not being more clear earlier.

TheForArkLD (763)

@Mathman05 oh then, u must use repl auth

Mathman05 (1)

@TheForArkLD is there a simple way of doing that?

TheForArkLD (763)

@Mathman05 idk, because idk how to use it.
it will help you probably.