Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am getting an error "Javascript compiler exception: missing ) after for-loop control (null.null.script; line 29)" which would be the instantiation of the loop. My syntax looks correct.
a little help please...
var ciArray = [];
var i;
var check;
for (i = 0; check = false; i < ciArray.length; i++) {
if(ciValue == ciArray[i,0]){
ciArray[i,1] += timer;
check =True;
}
if(i == mciArray.length-1 && !check) {
ciArray[i+1,0] = ciValue;
ciArray[i+1,1] = timer;
}
}
You have too many arguments for your for loop - looks more like a while loop with a check clause right now.
inside of condition the loop for you have (i = 0; check = false; <--- in this options it your error.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a simple code, its essence is to remove duplicate numbers from a sheet. But on my server, the data received does not match the data on leetcode. For what reason could this be?
var deleteDuplicates = (head) => {
for(let i = 0; i < head.length; i++) {
for(let a = i + 1; a < head.length; a++) {
if(head[i] === head[a] ) {
head.splice([a], 1)
}
}
}
return head;
};
console.log(deleteDuplicates([1,1,2]));
Output: [1,2]
Leetcode:
Your input
[1,1,2]
Output
[1,1,2]
Expected
[1,2]
How about using a Set? It's simpler and you'll avoid modifying a list that you're iterating over.
var deleteDuplicates = (head) => [...new Set(head)];
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my code but when i run this code in console always giving me Congratulations.
Help me for solve this problem.
var val=Math.floor(Math.random() * 10) + 1;
console.log(val);
var Predict = Number(prompt("Prediction ?"));
for(var i=1 ; i <= 3; i++){
if(Predict<val){console.log("Up")};
if(Predict=val){console.log("Congratulations") };
if(Predict>val){console.log("Down")}
}
Equal operator assigns the right hand to the left hand and so the result is always true! To compare two values use double equals like this:
if (Predict==val){console.log("Congratulations") };
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
var numberOfDrumButtons = document.querySelectorAll("button");
for(var i = 0; i<7; i++){
document.querySelectorAll("button")[i].addEventListener("click", handleClick);
function handleClick(){
alert("i Got Clicked");
}
}
console.log(numberOfDrumButtons.lenght);
whenever I run this command I get undefined as an answer in the console log.
This is a program that shows how many buttons are there in the program but the .lenght feature doesn't seem to work for me .
Basically you had a spelling mistake: "lenght" should be "length".
var numberOfDrumButtons = document.querySelectorAll("button");
for (var i = 0; i < numberOfDrumButtons.length; i++) {
document.querySelectorAll("button")[i].addEventListener("click", handleClick);
}
function handleClick() {
alert("i Got Clicked");
}
console.log(numberOfDrumButtons.length);
<button>B1</button>
<button>B2</button>
<button>B3</button>
<button>B4</button>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am doing a coding challenge where the letters in a string are replaced by their partner letters, I know that there is probably a better way to do this, but I just want to know why this doesn't work. Here is the code:
function DNAStrand(dna){
var strObject = {"A":"T", "T":"A", "C":"G", "G":"C"};
let newDna = "";
for (let i=0; i < dna.lenght; i++){
newDna += strObject[dna[i]];
}
return newDna
}
the function returns an empty string or "", the value of newDna before the loop, it doesn't change.
for (let i=0; i < dna.lenght; i++){
You made a typo. Change this to dna.length.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm creating a site and i needed to do some js. I'm not that good with it but tought i would figer it out. Not. I created a for loop but it does not run.
function order(user,product){
var index;
for(var i = 0; i<users.lenght; i++){
if(user == users[i]){
index = i;
break;
}
}
var budget = budgets[index];
alert(budget);
}
the creation of the users and budgets arrays are done with php and after checking with alert() it was how it should be.
Can anyone help me please?
lenght is spelt length. The misspelt property does not exist, so it undefined, which is equivalent to 0.