Check if an Element is Present in a Binary Search Tree(please help)

Tell us what’s happening:
Tell me what is wrong.

Your code so far


var displayTree = tree => console.log(JSON.stringify(tree, null, 2));
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
// change code below this line
this.isPresent=function(element){
  if(this.root===null){
    return null;
  }
  else{
    let pre=this.root;
    let ans;
    while(true){
      if(pre.value===element){
        ans=true;
        break;
      }
      else if(pre.value<element){
            if(pre.right!==null){
            pre=pre.right;
            }
            else{ans=false;break;}
        }
        else{
          if(pre.left!==null){
          pre=pre.left;
          }
          else{ans=false;break;}
        }
      }
    return ans;
  }

}
// change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36.

Challenge: Check if an Element is Present in a Binary Search Tree

Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/check-if-an-element-is-present-in-a-binary-search-tree

Hello, mohinder.

Have a re-read of the challenge instructions.

Write a method isPresent which takes an integer value as input and returns a boolean value for the presence or absence of that value in the binary search tree.

The keyword null is not of type boolean.

Hope this helps

Thanks it worked. :heart: