Why is the output "Sorry " even though my property is exist?

    var Student={   
      student_name:"Ricky",
      student_surname:"Martin",
      student_age:28,
      
      }
      function checkProp(Obj,prop){
        if(prop in Obj){
          return Obj.prop;
        }else{
          return "Sorry";
        }
      }
      console.log(checkProp(Student,Student["student_age"]));

Screenshot 2021-01-14 at 11.36.49

the value of Student["student_age"] is 28, so the function is checkig for a proeprty with name 28

2 Likes

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