Hi there. The seeded code provides you with an input element and assigns it to the idToText variable. That is to say the cells.find method returns an input element. We don’t want the input element itself. We’re only after the value property contained in the input element returned by cells.find method.
I’d reset the challenge to bring back the seeded code. From there I would focus on getting the value from the element returned by cells.find. If you have any further questions please let me know.
You don’t use value.find. That code wouldn’t work for two reasons. A number doesn’t have a find method. Number two even if it did, you would not be able to retrieve the element as you are comparing an ID to a value.
The actual answer is actually a lot simpler than that. I would recommend resetting back to the seed code. From there, I would retrieve the value on the object returned by the find method.
It should be like this. You should find cell first with matching to cell’s id inside to cells array with callback function. But function return cell element itself, you need the value of that input element. You can access to value like this, using value property.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
Your idToText function approach seems correct, you find to cell with id match and return to value of that but it may not be suitable for this lesson. If you recall the initial code of that stage, you’ll notice that the idToText function was nested inside the evalFormula function, and the lesson does not intend for this function to return anything that is this part of code is unneccessary.
The lesson aims to demonstrate how to write code that is clear and concise, with each line ideally returning a single value without the need for extra variable declarations or brackets. Therefore, if you adjust your idToText function to meet these requirements, you should be able to pass :).
You’re welcome. Sometimes coding can be very difficult, not just because of the code itself, but also because things may not always turn out as we expect or small differences can lead to significant results. That’s why developers always use version control systems. You can think of these lesson stages as your version control system, where your changes are not immediately applied to the client’s story request, even if the output wouldn’t change, you can revert your last change, reset the changes, and try again. You can do it🙂.
cells is an array of elements. If we jump to the end step, we can look at the evalFormula call site (usage). The second argument is the array of elements (cells parameter inside evalFormula).
So we call find on the array of elements (cells) and using the id parameter value passed to idToText when it is called we find the element. So the code from the previous step is.
const idToText = id => cells.find(cell => cell.id === id)
Now, instead of just returning the element which is what we do in the above code, we want that elements value property. We can dot onto the element find returns directly.
Example code with text elements and the innerText property (instead of input elements and the value property)