My JavaScript code is not functioning as expected

While practicing a course, I encountered a roadblock at this specific step. Unsure of where the issue lies. Any thoughts?

var todoList = {
  todos: [],

  displayTodo: function() {
    if (this.todos.length === 0) {
      console.log('todos are empty')
    } else {
      console.log("my todos: ");
      for (i = 0; i < this.todos.length; i++) { // Potential problem lies within this for loop
        if (this.todos[i].complited === true) {
          console.log("(X) " + this.todos[i].todoText);
        } else {
          console.log("( ) " + this.todos[i].todoText);
        }
      }
    }
  },

  addTodo: function(todoText) {
    this.todos.push({
      todoText: todoText,
      completed: false

    });
    this.displayTodo();
  },
  changeTodo: function(index, newValue) {
    this.todos[index].Text = newValue;
    this.displayTodo();
  },

  deletTodo: function(position) {
    this.todos.splice(position, 1);
    this.displayTodo();

  },
  toggelComplited: function(position) // This seems to be functioning correctly
  {
    var todo = this.todos[position];
    todo.completed = !todo.completed;
    this.displayTodo();
  }

};
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="style.css">
  <script src="script.js"></script>
</head>

<body>
  <h1>Greetings Bilal!</h1>
</body>

</html>

This is the output displayed in my console (refer to the comments below ==> //....):

todoList.displayTodo()

< Todos are empty

todoList.addTodo("first")

< My todos: < ( ) first

todoList.addTodo("second")

< My todos:

< ( ) first

< ( ) second

todoList.todos[ 0 ]

< {todoText: "first", completed: false}

todoList.todos[ 1 ]

< {todoText: "second", completed: false}

todoList.toggelComplited(0)

< My todos:

< ( ) first // Instead, it should display: (X) first

< ( ) second

Answer №1

There appears to be a mistake with the spelling of "completed" in the for loop

if (this.todos[i].**complited** === true) {

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

Filtering specific cameras using an ElasticSearch query

I am currently working on implementing a filter to sort out cameras that are linked with 'blueprints' from my camera database in MongoDB. The aim is to exclude cameras with type "BluePrint" from the filtration process. The specific part that nee ...

What are the steps to start using the Intersection Observer API right away?

Utilizing the Intersection Observer API, I can accurately determine whether an element is within the viewport or not. Is there a way to utilize the Intersection Observer API to detect if an element is in the viewport without relying on a callback function ...

Can selectors be grouped together for easier organization?

Seeking to style all child elements like div, table, ul, dl, under a specific selector using LESS. It would be great if I could do something along these lines. .myclass { ... &.otherClass > (div, ul, dl, table) { // define some rules... ...

Expanding Elements with CSS

I have a piece of HTML code as shown below <div> <div class="left"> </div> <div class="center"> </div> <div class="right"> </div> </div> .left { background: white; border-right: 1px s ...

Issues with the dropdown menu functionality occurring on a .Net6 MVC app razor page

I recently created a dropdown menu using bootstrap. It functions perfectly when I load an HTML file in VScode. However, I encountered an issue when I tried using the same dropdown markup in a .NET6 MVC app's .cshtml file. When I click on the dropdown ...

In the production and development environments, the interpretation of CSS classnames is being rearranged

Currently utilizing create-react-app v2. I've encountered an issue with a component that has multiple classnames: "x15 x14 login-form__field". Strangely, in the production build, the order of '.x14' and 'login-form__field' seems t ...

I'm having trouble adding a background image, even though I have set it to static. What could be

I attempted to add a background image to my Django website, but unfortunately, it was not successful. I followed the steps provided in this Stack Overflow answer here, however, it did not work. I even made changes to the database by migrating them, but s ...

Is it possible to utilize two different versions of a JavaScript library on a single page without causing function conflicts?

My current project involves using multiple versions of the Nvd3 library for different charts on a single page within an Angular application. Each chart is loaded through its own template and requires a specific version of Nvd3 (e.g., v1.8 for partial_1.htm ...

Best practices for making an AJAX call to fetch information from a database

I have a database containing a single table. The table includes columns for Company and Time, among others, with Company and Time being crucial. Users can make appointments by filling out a form. Within the form, there are 2 <select> elements - one ...

Retrieve the downloaded status of a blob within a specific function

I need a way to verify if the blob downloading process is finished when generating an excel file on the NodeJS server side in response to a request from the React frontend side. Is there a method or promise that can help me achieve this? I want to update t ...

Error encountered: JSON parsing failure at position 351 due to an unexpected token "}". This issue was found within the JSON object containing the property "license" with the value of "

I'm a newcomer to JavaScript and JSON, and I'm currently in the process of uploading my NPM package. However, I keep encountering an error when I attempt to publish it: Unexpected token } in JSON at position 351 while parsing near '..."lice ...

Can an EJS variable be transferred to an Angular ng-repeat filter?

I am currently working on a profile page where I need to display a user's name in plain text using <%= user.local.name %>. This requires querying the database through Mongoose. My issue now is figuring out how to pass that value to an Angular ng ...

Creating a unique JavaScript script that gradually adjusts the background color using the setTimeout() function

Is there a way to create a function that continuously changes the background color every 15 seconds by picking colors from an array that starts over once all colors have been used, without having the function run just one time? $(document).ready(() => ...

Fetching server-side data for isomorphic React app: A guide to accessing cookies

Currently, I am in the process of developing an isomorphic/universal React + Redux + Express application. The method I use for server-side data fetching is quite standard: I identify the routes that match the URL, call the appropriate data-fetching functio ...

Adding attributes to parent DOM elements of a component in Angular2: A Step-by-Step Guide

I'm working with the following code: ... <div class="container"> <div class="fancy"> <fancybutton></fancybutton> </div> <button (click)="addAttribute()">Remove</button> <button (click)="remAttr ...

Determine the standard query path by parsing the RESTful URL (Remove the resource identifiers) using JavaScript

I have a URL structure designed in RESTFUL format, for example: GET /street/:streetName/house/:houseNumber or GET /street/:streetName/house/listings. The placeholders :streetName and :houseNumber represent specific resources. I am looking to extract the co ...

What is the best way to position the wizard on both the left and right sides of the screen

Currently, here's the code I have, and I want it to appear like this. What are the steps needed to adjust the CSS in order to achieve that? .nav-wizard { display: table; width: 100%; } .nav-wizard > li { display: table-cell; text-align: ...

Recursive React Function for Rendering Components

I've been working on integrating a react-bootstrap component into a custom navBar component in my react project. I have a recursive function set up to render the components and drill down until there are no more NavItem components nested under the Nav ...

Is it possible to condense the coding of a vast array of objects into a more concise format?

Currently working on a personal project in react.js and aiming to write cleaner code. Is there a way to condense this code into just two lines or something similar? I attempted to create objects of arrays like const apps= {app_name:['Maps',&apo ...

Extract information from an external HTML table and store it in an array

I am looking for a way to extract data from an HTML table on an external site and save it as a JSON file for further manipulation. Is there a method to retrieve table data from an external HTML site that differs from the code example provided? Additional ...