how can I take a value of a variable in javascript and 'concatenate' in a <p> text in html?

Asked

Viewed 91 times

0

for example I have the following html code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jogo da memoria</title>
    <link rel="stylesheet" href="style.css">

</head>
<body>
    <div id="cardboard"></div>
  <p> :Score</p>
  <p><span id="valor"></span> :Score </p>

  <script src="main.js"></script>
</body>
</html>

and the javascript code:


var isMath1;
var jogadorScore;
const cardBoard = document.querySelector("#cardboard");
let cardHTML = "";
const imgs = [
  "C.png",
  "HTML.jpg",
  "Java.jpg",
  "JS.jpg",
  "php.png",
  "Python.jpg"
];


function colocartexto(){

  if(isMath1 == true){

    while(jogadorScore < images.length){
        jogadorScore++;






    }



  }
}


Estou tentando imprimir   o score do jogador  quando ele acerta na tentativa.

deste jeito:

           tipo -->      jogadorScore +:Score

2 answers

0

You can set the textContent property of the span element.

var valor = document.getElementById("valor");
valor.textContent = jogadorScore;

0

I believe you can also put the value inside the "p" tag without using the two Spans that Voce created. Try this way:


document.getElementById("valor").innerHTML = jogadorScore + ": Score";

And in HTML, you delete the two Spans and leave only the "p" tag, as follows:

<p id="valor"></p>

Browser other questions tagged

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