Error message: Unexpected end of input found in HTML, CSS, or JavaScript files

I am currently working on a card game project but I keep encountering an error that says "unexpected end of input". This error is completely new to me, so any assistance or guidance would be greatly appreciated. Additionally, the codepen isn't displaying anything and is also throwing the same error, along with the compiler in StackOverflow. Any help on this issue would be highly valued.

var turn = true;

var enemyCards = document.getElementById('enemy-cards');

var friendlyCards = document.getElementById('friendly-cards');

var friendlyHealth = document.getElementById('friendly-health-value');

var enemyHealth = document.getElementById('enemy-health-value');

var goodHealth=20;
var badHealth=20;

var enemyCardArray = [[2, 3], [2, 4]];

var friendlyCardArray = [[4, 3], [3,2]];

function initialSetup() {
  for (var i=0; i < enemyCardArray.length; i++) {
    var card = enemyCardArray[i]
    var damage = card[0];
    var health = card[1];
    enemyCards.innerHTML += "<div class='card'><h1 class='damage'>"+damage+"</h1><h1 class='health'>"+health+"</h1></div>"
  }

  for (var i=0; i < friendlyCardArray.length; i++) {
    var card = friendlyCardArray[i]
    var damage = card[0];
    var health = card[1];
    friendlyCards.innerHTML += "<div class='card'><h1 class='damage'>"+damage+"</h1><h1 class='health'>"+health+"</h1></div>"
  }
}

function setup() {
       enemyCards.innerHTML = "";//<--Set it to "" here, not in for loop
       friendlyCards.innerHTML = "";//<--Set it to "" here, not in for loop
       for (var i = 0; i < enemyCardArray.length; i++) {
            var card = enemyCardArray[i]
            var damage = card[0];
            var health = card[1];
            //enemyCards.innerHTML = "";
            enemyCards.innerHTML += "<div class='card'><h1 class='damage'>" + damage + "</h1><h1 class='health'>" + health + "</h1></div>";
                }

       for (var i = 0; i < friendlyCardArray.length; i++) {
              var card = friendlyCardArray[i]
              var damage = card[0];
              var health = card[1];
              //friendlyCards.innerHTML = "";
              friendlyCards.innerHTML += "<div class='card'><h1 class='damage'>" + damage + "</h1><h1 class='health'>" + health + "</h1></div>";
                }
            }

function battle() {
  if (turn === true){
    for (var i = 0; i<friendlyCardArray.length; i++) {
      if (friendlyCardArray.length == enemyCardArray.length){
        enemyCardArray[i][1] -= friendlyCardArray[i][0];
        if (enemyCardArray[i][1] < 1){
          enemyCardArray.splice(i, 1);
        }
      }if(friendlyCardArray.length>enemyCardArray.length){
        for (var i=0; i<enemyCardArray.length; i++){
          enemyCardArray[i][1] -= friendlyCardArray[i][0];
        if (enemyCardArray[i][1] < 1){
          enemyCardArray.splice(i, 1);
        }
       }
        for (var i=enemyCardArray.length+1; i>enemyCardArray.length; i++){
          badHealth-=friendlyCardArray[i][0];
          if (i == frienlyCardArray.length+1){
            break;
          }
        }
        
      }if(friendlyCardArray.length<enemyCardArray.length){
        for (var i=0; i<friendlyCardArray.length; i++){
          enemyCardArray[i][1] -= friendlyCardArray[i][0];
        if (enemyCardArray[i][1] < 1){
          enemyCardArray.splice(i, 1);
      }
    }
        
  }if (turn === false){
    
  }
}
initialSetup();
battle();
setup();
  
    
body {
  margin: 0;
  font-family: sans-serif;
  position: relative;
}

#enemy-cards{
  background-color: #873a00;
  width: 100%;
  height: 270px;
}

#friendly-cards{
  background-color: #873a00;
  width: 100%;
  height: 270px;
  position: fixed;
  bottom: 0;
}

.card {
  width: 150px;
  height: 250px;
  background-color: #afafaf;
  margin-top: 10px;
  margin-left: 10px;
  margin-bottom: 10px;
  position: relative;
  float:left;
}

.damage {
  text-align: left;
  position: absolute;
  bottom:0;
  left: 20px;
}

.health {
  text-align: right;
  position: absolute;
  bottom:0;
  right: 20px;
}

#friendly-health{
  float:left;
  width: 50%;
  background-color: lightgreen;
  height: 200px;
}
#friendly-health-value{
  position: fixed;
  left: 25%;
  vertical-align: middle;
  color: white;
}

#enemy-health-value{
  position: fixed;
  left: 75%;
  vertical-align: middle;
  color: white;
}

#enemy-health{
  float:left;
  width: 50%;
  background-color: #f73f27;
  height: 200px;
}
<div id="game">
  <div id="enemy-cards">
  </div>
  <div id="health">
    <div id="friendly-health">
      <h1 id="friendly-health-value">20</h1>
    </div>
    <div id="enemy-health">
      <h1 id="enemy-health-value">20</h1>
    </div>
  </div>
  <div id="friendly-cards">
  </div>
</div>

Answer №1

Check your code with JSHint and JSLint for errors and warnings. It's a helpful tool to improve your programming skills.

Answer №2

Enhanced Your JavaScript Code

var turn = true;

var enemyCards = document.getElementById('enemy-cards');

var friendlyCards = document.getElementById('friendly-cards');

var friendlyHealth = document.getElementById('friendly-health-value');

var enemyHealth = document.getElementById('enemy-health-value');

var goodHealth = 20;
var badHealth = 20;

var enemyCardArray = [
    [2, 3],
    [2, 4]
];

var friendlyCardArray = [
    [4, 3],
    [3, 2]
];

function initializeGame() {
    for (var i = 0; i < enemyCardArray.length; i++) {
        var card = enemyCardArray[i];
        var damage = card[0];
        var health = card[1];
        enemyCards.innerHTML += "<div class='card'><h1 class='damage'>" + damage + " <
            /h1><h1 class='health'>"+health+"</h
        1 > < /div>"
    }

    for (var i = 0; i < friendlyCardArray.length; i++) {
        var card = friendlyCardArray[i];
        var damage = card[0];
        var health = card[1];
        friendlyCards.innerHTML += "<div class='card'><h1 class='damage'>" + damage + " <
            /h1><h1 class='health'>"+health+"</h
        1 > < /div>"
    }
}

function setupGame() {
    enemyCards.innerHTML = ""; //<--Set it to "" here, not in for loop
    friendlyCards.innerHTML = ""; //<--Set it to "" here, not in for loop
    for (var i = 0; i < enemyCardArray.length; i++) {
        var card = enemyCardArray[i];
        var damage = card[0];
        var health = card[1];
        enemyCards.innerHTML += "<div class='card'><h1 class='damage'>" +
            damage + "</h1><h1 class='health'>" + health + "</h1></div>";
    }

    for (var i = 0; i < friendlyCardArray.length; i++) {
        var card = friendlyCardArray[i];
        var damage = card[0];
        var health = card[1];
        friendlyCards.innerHTML += "<div class='card'><h1 class='damage'>" +
            damage + "</h1><h1 class='health'>" + health + "</h1></div>";
    }
}

function startBattle() {
    if (turn === true) {
        for (var i = 0; i < friendlyCardArray.length; i++) {
            if (friendlyCardArray.length == enemyCardArray.length) {
                enemyCardArray[i][1] -= friendlyCardArray[i][0];
                if (enemyCardArray[i][1] < 1) {
                    enemyCardArray.splice(i, 1);
                }
            }
            if (friendlyCardArray.length > enemyCardArray.length) {
                for (var j = 0; j < enemyCardArray.length; j++) {
                    enemyCardArray[j][1] -= friendlyCardArray[j][0];
                    if (enemyCardArray[j][1] < 1) {
                        enemyCardArray.splice(j, 1);
                    }
                }
                for (var k = enemyCardArray.length + 1; k > enemyCardArray.length; k++) {
                    badHealth -= friendlyCardArray[k][0];
                    if (k === frienlyCardArray.length + 1) {
                        break;
                    }
                }

            }
            if (friendlyCardArray.length < enemyCardArray.length) {
                for (var l = 0; l < friendlyCardArray.length; l++) {
                    enemyCardArray[l][1] -= friendlyCardArray[l][0];
                    if (enemyCardArray[l][1] < 1) {
                        enemyCardArray.splice(l, 1);
                    }
                }

            }
            if (turn === false) {

            }
        }
    }
}
initializeGame();
startBattle();
setupGame();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging the power of Material-UI and React, modify the appearance of the "carrot" icon within the

Currently implementing MUI's textfield based on the information found at this link: https://mui.com/components/text-fields/. While there are numerous resources available for changing the font of the input text, I have not come across any documentation ...

Unexpected Display Issue with Angular Select Option

My goal is to implement the Select-Option Input as depicted in the first image link here: https://i.sstatic.net/SVT8R.png However, my current output looks different and I suspect that there may be a conflict between two CSS libraries. It's worth noti ...

Tips for contacting the giveaway host after the giveaway has finished

I am currently utilizing the Discord Giveaways module. I am interested in learning how to send a direct message to the host of the giveaway once it has ended. I haven't quite figured out how to do that yet. Here is what I have gathered so far: manag ...

Enhance the keyup search function to accept the input value as well

I currently have a keyup search function that works when a user types directly into the field. Here is the code snippet: if(this.$search_ele.length){ this.has_search = true; this.searchFn = this.buildSearchFn(opts.fields); this.bindEv ...

Looking for a way to utilize a Devise user account in an unconfirmed or locked state for AJAX interactions?

Currently, I am attempting to integrate the devise views utilizing JS to manage the responses. While I aim to utilize the default devise error messages, I am facing difficulty in isolating individual types of errors such as unconfirmed or locked accounts d ...

Is there a way to create a miniature camera or map within a scene in three.js without cropping the viewport?

Is there a way to create a mini-map or mini-cam using three.js? The idea is to have two camera views - one mini-map or "mini-cam" in the top right corner (as shown in the image) and the main camera view covering the rest of the scene without the border. ...

Error: Unable to change image -- TypeError: Cannot assign value to null property 'src'

As I work my way through the textbook for one of my classes, I am practicing by building an image swapping page. The concept is simple - clicking on a thumbnail swaps out the main image and enlarges it as if it were linking to another web page. Despite fol ...

Tips for creating inline links

Data is taken from a table using $number and printed as follows: echo "<div class='pagination'><a href='page_pagination.php?number=". $number ."' > ". $number ." </a></div>"; The output does not display in one ...

Loop through ng-options using ng-repeat that are linked to the same ng-model

This situation may seem odd, but I am willing to adjust the API Data if necessary. My requirement is to have multiple dropdowns sharing the same ng-model. The Question: Why does ng-model become unique when using the same variable name? How can I ensu ...

Switch between active tabs (Typescript)

I am working with an array of tabs and here is the code snippet: const navTabs: ITab[] = [ { Name: allTab, Icon: 'gs-all', Selected: true }, { Name: sources.corporateResources, Icon: 'gs-resources', Selected: false }, { Name ...

How to transform HTML content into plain text format while retaining the HTML tags

transform this into something like this2 I'm attempting to convert text containing html tags (p, ol, b) into plain text format (similar to the outcome of running a code snippet) - I've experimented with the following code in .net core but it only ...

What is the reason behind receiving the error message "`Foo` only represents a type, but is being treated as a value here" when using `instanceof` in TypeScript?

As the creator of this code interface Foo { abcdef: number; } let x: Foo | string; if (x instanceof Foo) { // ... } Upon running this code, I encountered an error in TypeScript: 'Foo' is recognized only as a type and cannot be used a ...

Troubleshooting HTTP Issues in Angular 2

I am currently facing an issue with my Angular 2 project's Http functionality. I have defined it as a parameter in the constructor, but it keeps printing as undefined. Below is the snippet of code from my project: import 'rxjs/add/operator/toPro ...

Adding a unique component to a Spring Boot application with Thymeleaf integration

My navigation bar includes a list with a dropdown feature. When the user clicks on the dropdown entry, I want to display a snippet of another HTML page within the project. The navigation bar HTML code is as follows: <div th:fragment="navbar"& ...

Expanding a table by including a new column using Node.js and Knex

Currently building a service for my router using Node.js and Knex, but I'm struggling to add a column to an existing table. Any assistance would be greatly appreciated. Even though I am working with PostgreSQL, I believe the solution will be similar r ...

Modifying several items with Ramda's lens

I am currently working with a data structure that is structured similarly to the following: var data = { "id": 123, "modules": [{ "id": 1, "results": [{ "status": "fail", "issues": [ {"type": "ch ...

Customize the appearance of alert boxes in ajax requests

Is there a way to customize the default ajax alert box? I currently have code that deletes a user and reloads the current page. It functions properly, but I want to enhance the styling of the alert box that appears before the user is deleted. function d ...

not getting any notifications from PHP

Despite receiving a status of '1' from this process file, my JavaScript code seems to be working fine. However, I am facing an issue with not receiving the email. <?php //Retrieve form data. //GET - user submitted data using AJAX //POST - in ...

Prevent the SnackBar from extending to full width in case of a smaller window size

Is there a solution to prevent the SnackBar from spanning the entire width of the screen when the window is narrow? ...

Retrieving data from a dynamic form using jQuery

Can someone assist me with the following issue: I have a dynamic module (generated by a PHP application) that includes input fields like this: <input type="text" class="attr" name="Input_0"/> <input type="text" class="attr" name="Input_1"/> ...