Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line 27 #175

Closed
ranjanrnj44 opened this issue Dec 28, 2019 · 3 comments
Closed

Line 27 #175

ranjanrnj44 opened this issue Dec 28, 2019 · 3 comments

Comments

@ranjanrnj44
Copy link

In line 27 if I'm making it's value empty it is not working,
Something like this ('' => ' ')

input.value = ''; => input.value = " "; //this statement show's can't find if I left space in-between " "

In the eg code line 27 with space in-between (" ") and run the code, in input field 2nd try error occurs all the time

@chrisdavidmills
Copy link
Contributor

Which example are you referring to? "Line 27" doesn't really help me ;-)

Anyway, I'm guessing that you are looking at an example featuring a form input element, and in the JavaScript we are checking whether the input is empty or not.

input.value = '' checks whether the input is empty, i.e. if its value is an empty string.

input.value = ' ' on the other hand is checking whether the input value is equal to a single space character, so will fail if it is anything else.

Does that answer your question? If not, please give me some more details, and I will help you further.

All the best.

@ranjanrnj44
Copy link
Author

"Sorry I forgot to post the code"

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
  </head>

  <body>
   <label for="search">Name : </label>
  <input id="search" type="text">
  <button>Search</button>

  <p></p>
    
    <script>
     let input = document.querySelector("input");
      let btn = document.querySelector("button");
      let para = document.querySelector("p");

      btn.addEventListener(`click` , function(){
        let val = input.value.toLowerCase();
        //console.log(val);'
   input.value = "";
        input.focus();
        let contacts = [`ranjan:12345` , `jan:78906` , `ran:56882`];
        for(let i=0 ; i<contacts.length ; i++){
          let contact = contacts[i];
          //console.log(contact);
          let split_it = contact.split(":");
          //console.log(split_it);
          if(val === split_it[0].toLowerCase()){
            para.textContent = `So, you're looking for ${split_it[0]} of ${split_it[1]}`;
            break;
          }
          else{
            para.textContent = `Sorry, couldn't find the result`;
          }
        }
      });
    </script>
  </body>
</html>

input.value = ""; (is the line) . And now I'm clear by our explanation, It was really helpful, Thank you.

@chrisdavidmills
Copy link
Contributor

Good, glad it helped ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants