Short answer
Asking how to make a text-based game is essentially asking how to program. Learn to program.
Long version
Learn programming
Writing text-based games is a good way to learn.
This is the hard part. This is going to take time.
The first thing any game needs is a loop, input, output and something that converts input to output. This is what that would look like in Lua:
-- Process input into output
function process(i)
if i == "hi" then return "Hi to you too, player." -- Player greets
elseif i == "exit" then return -1 end -- Player wants to quit
-- ...add more cases here...
end
-- Main loop
while true do -- loop over these things
local input = io.read() -- read input
local output = process(input) -- process it
if output == -1 then -- if it was a quit instruction
os.exit() -- quit
else
print(output) -- show output
end
end
Figure out what that is doing and why.
When you realise you need state, look into variable assignment.
When you realise you need collections of things like an inventory, look into data structures like arrays and lists.
By then, you essentially know how to program.
Good luck!
For making a full game, you may want to write Python or JS instead. By the time you know how to program, it shouldn't matter much. Their syntax is very similar and the ideas always matter more than the syntax.
Same in JS
Since you know JS, here's a similar seed for a JS-based text adventure:
<html>
<head>
<title>Sample game</title>
</head>
<body>
<form onSubmit="go();return false;">
<input id="input-textbox" type="text" />
<input type="submit" />
</form>
<textarea id="output-textbox" rows="20" cols="50"></textarea>
<script>
textIn = document.getElementById("input-textbox");
textOut = document.getElementById("output-textbox");
function process(input) {
if (input == "hi") { return "Hi to you too, player."; }
else if (input == "exit") { return "No."; }
}
function go() {
var input = textIn.value;
textIn.value = "";
var output = process(input);
textOut.value += output + "\n";
}
</script>
</body>
</html>
JSFiddle is handy for developing HTML/CSS/JS sketches and sharing them around. MDN and WebPlatform are my favourite web-dev resources.