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 29 days ago. Improve this question
Tag: for-loop
return statement in function that convert decimal to binary numbers
I’m trying to understand how to use functions in JS. This code converting decimal numbers to binary numbers: but when I’m trying to put this code into a function, the function returns only the first or the last value. What am I doing wrong? Answer You have to store the result of each iteration in array. Also you should declare
Transform JSON into required format
Here is my input JSON I need to transform json w.r.t parent category and what ever child json elements w.r.t parent to be in one format. All should be dynamic no hard coding comparing with strings. Need to transform my input json to below sampleformat, I tried separating parents and child values in an array and loop it and push.
JavaScript for loop issue affects guess count
so I’m trying to build a JavaScript hangman game and I’m having a problem with my checkMatch function. what I’m trying to achieve is for it to check against the hiddenChoice array and only run the code in the else if statement if this.id isn’t in the array at all. currently if hiddenChoice = apple and this.id = l it
Getting odd results from a for loop inside a filter function
I’m looping inside a filter. I want to get the values from my vals array plus the keys(name, description) for my filter. When I iterate through my vals array, I keep getting returned the name but not the key. Ideally I would like the return method to give me key and value. return x[this.searchValues[i]].includes(‘phil’) to be return x.name.includes(‘phil’) return x.decription.includes(‘phil’)
How to log how many possibilities fulfil the if statement javascript
I’m trying to log how many items from the array fulfil the condition. the output I’m looking for is : 6 (because 6 of the numbers are equal or greater than 8) tried let count = 0; for (let i = 0; i < grades.length; i++) { if (grades[i]>= 8){ count++ } Answer
date copy stops the loop statement to function as intended
What i am trying to do is to display available rooms which are in data i map the rooms using data.map , check if one is available between a given ( checkin and checkout date ) using availdata[p.roomId][date].i==0 , if not it will display the available room . the code works fine but as soon as it finds an available
IF/ELSE condition not working properly and Rerendring duplicates React
My goal here is to check a checkin and checkout date and see if a room is available or not if availdata[p.roomId][date].i==0 then the room at that range of dates is not available so it will be displayed as not available if not it will check its price with availdata[p.roomId][date].p1 and display it with a price instead in my case
Comparing length of strings in an array?
Hi I’m trying to compare the length of each word in a sentence. I converted this sentence into an array but then I’m lost in my codes. I tried 2 methods – for loop and reduce(), but neither worked. What happened in my code? Reduce() => This one gave me undefined when I try to run the function. I gathered
Javascritpt – Looping through an array
So i just started learning js and i can’t solve this excercise: Create a file named looping-through-arrays.js. In that file, define a variable named pets that references this array: [‘cat’, ‘dog’, ‘rat’] Create a for loop that changes each string in the array so that they are plural. You will use a statement like this inside the for loop: pets[i]