vmars316 Posted March 4, 2016 Share Posted March 4, 2016 Hello & Thanks , var player1Score = 10; var player2Score = 20; document.getElementById('keepScore').innerHTML = ' player2Score = ' + player2Score; I want to be able to display several items on one line with the above code or preferably something that works . Pls , how can I do this . Thanks Link to comment Share on other sites More sharing options...
Ingolme Posted March 4, 2016 Share Posted March 4, 2016 You can add as much content to the innerHTML property as you want. What have you tried? Link to comment Share on other sites More sharing options...
vmars316 Posted March 4, 2016 Author Share Posted March 4, 2016 Thanks , this is what i am trying to get to run : document.getElementById('keepScore').innerHTML = ' player2Score = ' + player2Score; but when I get this to work , i will have 4 players , player1 -player4 . Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2016 Share Posted March 4, 2016 You use the + operator to join text like that, you can do it as many times as you'd like. Link to comment Share on other sites More sharing options...
vmars316 Posted March 5, 2016 Author Share Posted March 5, 2016 I couldn't get the crazy thing working so I did this instead: <div> <table style="width:100%"> <tr> <td width="10%"> totalScore = </td> <td id="totalScore" width="5%"> </td> <td width="8%"></td> <td width="10%"> oops! = </td> <td id="oopsScore" width="5%"> </td> <td width="8%"></td> <td width="10%"> totalHits = </td> <td id="totalHits" width="5%"> </td> <td width="8%"></td> <td width="10%"> totalShots = </td> <td id="totalShots" width="5%"> </td> </tr> </table> </div> Thanks Link to comment Share on other sites More sharing options...
vmars316 Posted March 7, 2016 Author Share Posted March 7, 2016 Oops , I see my error : I need a separate document.getElementById('item#').innerHTML = for each item# . Thanks Link to comment Share on other sites More sharing options...
dsonesuk Posted March 7, 2016 Share Posted March 7, 2016 Why not use array <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var items = [["player1Score", 10],["player2Score", 20]]; //to add extra item items[2]=["player3Score", 30]; var join=""; for(i=0;i<items.length;i++){ join+= items[i][0]+"= "+items[i][1]; if(i<items.length-1){ join+=", "; } else { join+="." } } document.getElementById("demo").innerHTML =join; </script> </body> </html> 1 Link to comment Share on other sites More sharing options...
vmars316 Posted March 7, 2016 Author Share Posted March 7, 2016 Thanks! dsonesuk That goes in my snippets folder . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now