JavaScript Splice Object from Array - undefined error splice object from array,splice object from array typescript,splice

Within the code below contains a very simple question game (work-in-progress). So far, I've been able to have a "Rules" message appear through the onLoad function, "qDisplayLoad()". Next, the onClick function "qDisplayClick" runs anytime someone clicks, thus randomly pulling from the array (qArray).

My question: How do you remove (splice) the question chosen from the array once it has been shown? My goal is to not have the same question repeat twice. Within the code below, you will find my amateur attempt at "splice" (and it kind of works), but instead, the array pushes out "undefined".

var qLoad = 0;
var qArray = [
    "Question 1",
    "Question 2",
    "Question 3",
    "Question 4",
    "Question 5"
];


var randomElement;

/* The text "Rules" appears when the page loads */
function qDisplayLoad() {

    if (qLoad == 0) {
        randomElement = "Rules";
        qLoad = 1; /* Changes qLoad to "1" from "0" so the array begins within the "qDisplayClick" function */
    }

    document.getElementById("questions").innerHTML = randomElement;
}

/* A new question is pulled from the array everytime the mouse is clicked (up to a maximum of 5) */
function qDisplayClick() {
    var randomNumber = Math.floor(Math.random() * qArray.length); /* Questions are randomly chosen and rounded down from the array */

    if (qLoad += 1 && !(qLoad == 7)) {
        qArray.splice(qArray,1);
        randomElement = qArray[randomNumber];

    } else if (qLoad == 0) {
        randomElement = "Rules";
    }
    if (qLoad == 7) { /* After the 5th question, text will appear for the pop up */
        randomElement = "WIP - POP UP PLACEHOLDER";
    }

    document.getElementById("questions").innerHTML = randomElement;
}
Answer:1

The error comes from this line qArray.splice(qArray,1); The splice method can't take an array as the first parameter:

array.splice(index, howmany, item1, ....., itemX)
  • index Required.
  • howmany Optional.
  • item1, ..., itemX Optional. The new item(s) to be added to the array
Answer:2

So basically when i hover over "drive" option which is a h1, i want a div container to appear that contains several other in detail options. Then if i click on "ride" option which is another h1, i ...

So basically when i hover over "drive" option which is a h1, i want a div container to appear that contains several other in detail options. Then if i click on "ride" option which is another h1, i ...

  1. change style element javascript
  2. change style element jquery
  3. change style element js
  4. change style element
  5. change style element angular
  6. change style element angularjs
  7. change element style css
  8. change element style react
  9. change element style typescript
  10. change element style using javascript
  11. change element style angular 4
  12. change element.style wordpress
  13. change element style in iframe
  14. change element style on click
  15. change element style class javascript
  16. change element style inside iframe
  17. change element style html
  18. change element style using jquery
  19. change element style color
  20. change style dom element

I have something like this: = f.input :payment_date, as: :date = f.input :tuitor, as: :boolean, label: 'Tuitor payment' and I want use on this a simple JavaScript like this: costam = -> if ...

I have something like this: = f.input :payment_date, as: :date = f.input :tuitor, as: :boolean, label: 'Tuitor payment' and I want use on this a simple JavaScript like this: costam = -> if ...

I was racking my head for a whole night trying to figure out why my code isn't working. I copied the code 2 times but the result was the same. The problem was sometimes when the snake eats an apple, ...

I was racking my head for a whole night trying to figure out why my code isn't working. I copied the code 2 times but the result was the same. The problem was sometimes when the snake eats an apple, ...

  1. snake game not working
  2. snapchat snake game not working
  3. google snake game not working
  4. working snake game

When I do new Date() I get: Thu Dec 28 2017 10:17:58 GMT+0800 (台北標準時間) If I apply .valueOf() to that date I get: 1514427724039 Which is what I want. Now, I need to apply .valueOf() to a date ...

When I do new Date() I get: Thu Dec 28 2017 10:17:58 GMT+0800 (台北標準時間) If I apply .valueOf() to that date I get: 1514427724039 Which is what I want. Now, I need to apply .valueOf() to a date ...