Javascript displays no value on screen

Asked

Viewed 32 times

1

Good morning, good afternoon and good night!

I’m developing a cli style question and answer game in HTML and Javascript. But my javascript function does not display the answer on the screen. Follows the code:

funcaoJogo = function(){
	document.getElementById('tela').innerText = document.getElementById('inputValor').value;
	alert("Bem vindo a Cidade das Batalhas");
}
body {
 background-color: gray;
 color: white;
}

div#tela {
	margin: auto;
	padding: auto;
	background-color: black;
	width: 640px;
	height: 480px;
	overflow: auto;
	color: white;
	text-align: center;
}

div#resposta {
	margin: auto;
	padding: auto;
	background-color: #B22222;
	width: 640px;
	height: 25px;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>

<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>IA GAME</title>

<link rel="stylesheet" type="text/css" href="css2/newCss.css">
<script type="text/javascript" src="javascript2/newJavascript.js"></script>

</head>

<body>
<div id="tela">
</div>

<div id="resposta">
<center>
		Jogador Nº1:
		<input id="inputValor" type="text" name="">
		<button id="enviar" onclick="funcaoJogo">Desafiar</button>
</center>
</div>

</body>
</html>

If anyone can help me thank you! Thanks, said!

1 answer

2

Missing parentheses in the onclick, needs them to call the function

funcaoJogo = function() {
  document.getElementById('tela').innerText = document.getElementById('inputValor').value;
  alert("Bem vindo a Cidade das Batalhas");
}
<div id="tela"></div>

<div id="resposta">
  <center>
    Jogador Nº1:
    <input id="inputValor" type="text" name="">
    <button id="enviar" onclick="funcaoJogo()">Desafiar</button>
  </center>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.