Logical Programming Questions In Javascript