Error involving an array of objects with a two-dimensional array property

Seeking assistance here as a final resort, I've dedicated over 50 hours trying to resolve this persistent error. Any help would be truly appreciated.

Error: "Decunstructing Assignments are not supported by the current version of Javascript", "Expecting a semicolumn or newline".

Objective: Assign user input within a for loop to variables and utilize those variables to set object properties for each element in the object array.

function STUDENT(name, id, course, mark, sum)
    {
        this.studName = name;
        this.studentID = id;
        this.courses = course;
        this.marks = mark; //Attempted new array and marks[courses][0]
        this.studsum = sum;
    }

var student = new Array(30);

for(i = 0; i < 30; i++)
    {
       var name1 = prompt("Enter Student Name:");
        if (name1 !== "!!!")

            {
                var id1 = parseInt(prompt("input the students ID:", ""));

                for (var l = 0; l < course.length; l++)
                {
                    mark1[l] = parseFloat(validateMark(l));
                    sum1 += mark1[l];
                    coursesum[l] = mark1[l] + coursesum[l];
                }

                var student[i] = new STUDENT(name1, id1, course1, mark1, sum1);
                /*ERROR IS HERE ^*/


            }

    else
        i = 30; /*Breaks out of loop*/
    }/* end of for loop*/

I have explored various options, yet this remains the core of my code; all other functions perform correctly, console.log() displays each variable as expected.

Your guidance is greatly appreciated.

Answer №1

Revise the following code snippet:

let student[i] = new STUDENT(name1, id1, course1, mark1, total);

to:

student[i] = new STUDENT(name1, id1, course1, mark1, total);

The array 'student' is already initialized so there's no need for 'let' before it.

Note: The 'course' variable within your loop is currently undefined in the existing code.

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

Fancybox fails to open when clicking on the submit form

I am having an issue with the fancybox not appearing after submitting my form. Below is the code I have for the fancybox: <div class="hidden" id="fancybox-popup-form"> (your Fancybox content goes in here) </div> <style> .hidd ...

Switching JButton Icon when Clicked

I am working on developing a Java JFrame Application that resembles Minesweeper but with some unique rules and objectives. Currently, I have set up a grid of JButtons in a 12x12 layout using a JButton 2D array. My goal is to change the image displayed on ...

Unable to load physi.js and ammo.js due to a loading error

I'm currently working on a project involving physijs, but I keep encountering a specific error in Mozilla Firefox console: NetworkError: Failed to load worker script at "js/libs/ammo.js" https://i.sstatic.net/C41T8.png I've been trying to tro ...

Pressing the enter key within Material UI Autocomplete will allow you to quickly create new

Wouldn't it be great if Autocomplete in material ui could do this: wertarbyte Imagine being able to insert text (string) without the need for a list of elements to select from. This means that the noOptions message shouldn't appear, and instead ...

Fixing 500 (Internal Server Error) in Vue.js and Laravel: The Ultimate Guide

Working on a university project using Vue.js and Laravel, I need assistance with sending information to the API. I'm trying to use axios for the POST request, but it's giving me an error: 500 (Internal Server Error). I can't seem to identif ...

The execution of the create event function occurs during the act of creation

I've been searching for an answer to my issue below, but it seems like the keywords I used might have been too vague. So, I'm reaching out to you for help. I am attempting to create a click outside menu close function using this code snippet her ...

Issue with Ajax reload functions malfunctioning

Embarking on a new journey, I am diving headfirst into the world of web development. As an artist and writer, I have recently delved into the realm of creating a project that integrates a cms, project manager, and database front-end using php, mysql, and j ...

Leverage PHP server variables in JavaScript

I am facing a situation where I have multiple values stored in a database table that need to be used as parameters in Javascript. Instead of using inline scripts, my approach is to create a 'parameters.php' file that retrieves and returns all the ...

Tampermonkey script automating login encountered a POST 404 error

REVISION (click here *) I developed a basic auto login script using Tampermonkey for // ==UserScript== // @name 7Mind User Login Website // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! / ...

Calculate the sum by multiplying each element in a nested array by a specific value, then combining the products

I need to multiply each "column" in an array by a specific number, and then sum up the results for each "row". While I was able to achieve this for a single array, I am struggling with applying it to a 2d-array. The approach needs to ...

Exploring Angular's ngFor feature in building a dynamic accordion menu that automatically closes one panel and opens another when clicked

The Angular Material accordion component is a key feature in my Angular project. Utilizing an ngFor loop to iterate through the information stored in menuItems, I dynamically create a new expansion panel for each item. With two components in play, I seaml ...

Verifying Initialization Before Destructing jQuery File Upload

I'm currently working with the blueimps jQuery file upload plugin and I need to delete all existing instances before creating new ones. The issue I'm running into is that I receive an error when attempting something like this: $('.upload&ap ...

How the Material-UI Tooltip zIndex takes precedence over the MenuItem in the Select component

My issue is quite straightforward. I have a <Tooltip> component wrapping a <Select> component, and when I click the Select, the tooltip appears above the MenuItems like this: Expected behavior: https://i.sstatic.net/VOVmf.png Unexpected beha ...

Issue: [Issue: ENOENT: the file or directory './1695556319341.mp3' does not exist]

I am currently facing an issue while trying to convert an mp4 file to an mp3 file and then uploading it directly to Firebase storage without saving it locally on my machine. The error I encounter is "Error: [Error: ENOENT: no such file or directory, open ...

Working with Express and Typescript: When using `Res.status(200)`, the error "Type 'Number' has no call signatures" may arise

Recently, I've been delving into typescript and experimenting with making an Express server work with it. My goal is to execute the code below after retrieving data using axios: import express, { Response, Request } from 'express' (...) app. ...

Exploring a recursive approach for searching through a dictionary connected to arrays that run in parallel?

Currently, I am in the process of developing a recursive function to search a dictionary that represents specific locations along a river. This dictionary utilizes four parallel arrays with start as the key. Parallel Arrays: start = location of the endpo ...

Enter a socket.IO chat room upon accessing an Express route

Encountering difficulty when attempting to connect to a socket.IO room while accessing a specific route in my Express application. The current setup is as follows: app.js var express = require('express'); var app = express(); var http = requir ...

Are there any JavaScript tools for adding notes to text?

I’ve searched online but haven’t had any luck. Is there a tool available that allows for annotating text selections, even those that overlap? The scenario is that multiple users will be given the same text and need to annotate different selections in ...

JavaScript requires a function to be passed as an argument

I've been struggling to make this particular JavaScript function work, but so far I haven't had any success. Every time I try to call the confirm dialog, I keep receiving an error saying "function expected." Could someone please point out what ...

Vue.js 2 components encountering issue with parent-child relationship due to undefined item

I recently started working with Vue and encountered the error referenceError: items is not defined. Can anyone help me figure out why this error is occurring or provide some guidance? Upon initial inspection of the code, it seems like the issue may be rel ...