JavaScript hasOwnProperty Usage

hello, am having issue completing this little route project.
If I run the first function independent it has no problem, but calling the function in the next function it display error.that prop can’t iterate what should I do please.

//Array of integers for searching maximum integer 
const mixItems = [2,6,96,35,6];

   const itemsObj = {
  "Biscuits": 12,
  "Bread": 94,
  "Danon_milk": 16,
  "Golden_morn": 50

 //Helper function to find the maximum integer 
  function eventHandler(par){ 
  let maxValSearch = [];
maxValSearch = [...par];
 var maxVal = par.reduce(function(initEl,finEl){
 maxValSearch = ([initEl,finEl]);
return Math.max.apply(null,maxValSearch);
    return maxVal;
//other function 
const itemsFunction = function(obj,prop){
totalSellParItem = " ";
  for(let i in obj){
     prop = i;
     result = obj[prop];
     if(result !== undefined){
       totalSellParItem = result;
      let totalBisPrice = eventHandler();
       return totalSellParItem += totalBisPrice;
     }else {
       return "result of the property not found ";
   }else {
     return "this property is not found ";
   return totalSellParItem;
  let propPrompt = prompt('enter the property here');
const eventHandlers = itemsFunction(itemsObj,propPrompt)
window.alert(eventHandlers +":"+ 'searching... ');

I moved your question to its own topic because you were asking a question related to your own code for a challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s). Also, it is advisable to use the Ask for Help button on the challenge, so it auto-populates with your current code and the challenge url, if this relates to the freeCodeCamp curriculum.

Thank you.

1 Like

HI @ychris!

For the first function here

I feel like it would be easier, to just use the spread operator instead.

let maxNum = Math.max(...mixItems);
console.log(maxNum) // result is 96

As for your second function, I am struggling to understand your logic behind it.
So maybe someone else can you assist you with that part.

Also, did you mean to write an arrow function here?

const itemsFunction = (obj,prop)=>{


^ It’s just a normal function expression. Arrow function are also function expressions.

1 Like

I have never written it that way.

1 Like

Most people will not write it like that anymore. They would use an arrow function or just a normal function declaration.

If you look at older JS code you will see it used fairly often (if you see it you will likely also see some var declarations in the code).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.