Fixed my displayblock problem but I think my output has a conditional statement error

why is my else statement not working python
why is my else statement not working java
why is my if else statement not working
what will a computer do if the if condition turns out to be true?
why is my if statement not working python
why is my if statement not working java
3 why does my code not recognize the if else lines and fall through to the then code line
fill in the blanks to create a valid if else if statement

So I am trying to get my userprompts to displayblock and my userstory and usererror to display none before the user has entered their inputs. I don't understand where I went wrong with my script

Edit: So I got my displayblock to work (thanks for that guys) but I tried to add a conditional statement to make sure the user enters all the fields and now my error pops up on the page before any input is entered. Any assistance is appreciated

     const userprompts = document.querySelector("#prompts");
    const userstory = document.querySelector("#story");
    const usererror = document.querySelector("#error");

    const submit = document.querySelector("#submit");
    submit.addEventListener("click", completestory, false);

    const reset= document.querySelector("#reset");
    reset.addEventListener("click", resetPage, false);

    document.querySelector('#name').focus();

    const thename = document.querySelector("#name");
    const firstverb = document.querySelector("#firstverb");
    const firstnoun = document.querySelector("#firstnoun");
    const adjective = document.querySelector("#adjective");
    const secondnoun = document.querySelector("#secondnoun");
    const adverb = document.querySelector("#adverb");
    const place = document.querySelector("#place");
    const storyOutput = document.querySelector("#storyOutput");

    userprompts.classList.add("displayBlock");
    userstory.classList.add("displayNone");
    usererror.classList.add("displayNone");

    function checkStory() {
      if (thename.value == "" && firstverb.value == "" && firstnoun.value == "" && adjective.value == "" && secondnoun.value == "" && adverb.value == "" && place.value == "") {
        error.classname.add("displayBlock");
        return false;
      }
      else {
        return true:
      }
    }

    function completestory() {



      let finishedstory = "";
      finishedstory += "There once was a person named " + thename.value + ". ";
      finishedstory += "One day, " + thename.value + " was " + firstverb.value + " out in the "
      + firstnoun.value + ". ";
      finishedstory += "All of a sudden, " + thename.value + " saw a " + adjective.value +
      " dragon! " ;
      finishedstory += thename.value + " thought for a second and did the only thing that came to mind "
      + " and grabbed a " + secondnoun.value + ". " ;
      finishedstory += "With the " + secondnoun.value + " in hand, " + thename.value + " jumped up and " + adverb.value + " attacked the dragon.";
      finishedstory += " The dragon became very confused and left. Our hero returned to their ancestral home of " + place.value + " ." +  " The End?";

      storyOutput.innerHTML = finishedstory;

      userprompts.classList.add("displayNone");
      userstory.classList.add("displayBlock");
      usererror.classList.add("displayNone");
      userprompts.classList.remove("displayBlock");
      userstory.classList.remove("displayNone");
      usererror.classList.remove("displayBlock");

      if (checkStory == false); {
        return;

      }

    }

    function resetPage() {
      userprompts.classList.add("displayBlock");
      story.classList.add("displayNone");
      error.classList.add("displayNone");
      userprompts.classList.remove("displayNone");
      userstory.classList.remove("displayBlock");
      usererror.classList.remove("displayBlock");
      thename.value = "";
      firstverb.value = "";
      firstnoun.value = "";
      adjective.value = "";
      secondnoun.value = "";
      adverb.value = "";

      storyOutput.innerHTML = "";

      thename.focus();

    }
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <link rel="stylesheet" href="Mod3Layout.css">
    <meta charset="utf-8">
    <title>Sean's Mad Lib</title>
  </head>
  <body>
    <h1> Sean's Wacky Mad Lib</h1><hr>

    <div id="prompts">
      <h3>Please enter your prompts here</h3>
      <p>Enter a name here:
        <input id="name" type="text" placeholder="name">
        </p>
        <p>Enter a verb here:
          <input id="firstverb" type="text" placeholder="verb 1">
          </p>
          <p>Enter a noun here:
            <input id="firstnoun" type="text" placeholder="noun 1">
            </p>
            <p>Enter an adjective here:
              <input id="adjective" type="text" placeholder="adjective">
             </p>
             <p>Enter another noun here:
               <input id="secondnoun" type="text" placeholder="noun 2">
             </p>
             <p>Enter an adverb here:
               <input id="adverb" type="text" placeholder="adverb">
             </p>
             <p>Finally, Enter a place here:
               <input id="place" type="text" placeholder="place"
               </p><br>
             <button id="submit" type="button">Submit</button>
             <p id="error">You did not answer all the questions. Please try
               again</p>
      </div>
      <div id="story">
        <p>Let's see what you wrote.</p>
        <p id="storyOutput">Hello Dave</p>
        <button id="reset" type="button" name="Reset">Reset</button>
        </div>

By using jquery you can apply css. Please refer the code below

sample code to apply css using jquery.

$("#prompts").css("background-color", "yellow");

sample code to apply class name jquery.

$( "#prompts" ).addClass( "displayBlock" );

you can even remove and add class at the same time.

$( "#prompts" ).removeClass( "displayNone" ).addClass( "displayBlock" );

if / else errors, If you have a question that isn't answered here, please use the green “Ask a Depending on what you are checking for, the else if and else blocks may not be needed. I think you can see what I'm getting at. My error was that I used a statement on Else. The most simple conditional statement (1) looks like this: Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

In vanilla JS, I would recommend to use .style property to change anything in the CSS.

Example :

document.getElementById("myDIV").style.display = "none";

Source :

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style https://www.w3schools.com/jsref/prop_style_display.asp

But in your case, you are trying to add a class.

For adding a class in vanilla JS, I would recommend the classList method.

Example for adding :

const element = document.querySelector("#myDIV");
element.classList.add("mystyle");

Example for removing :

const element = document.querySelector("#myDIV");
element.classList.remove("mystyle");

Source :

https://www.w3schools.com/howto/howto_js_add_class.asp https://www.w3schools.com/howto/howto_js_remove_class.asp

Some Tips, Tricks, and Common Errors — How to Think Like a , And if we get to the end of any function and we have not explicitly executed any return statement, Python automatically returns the value None. want to know if some condition holds for any item in a list, e.g. “does the list have any To find the second problem above, consider what happens if you call this function with an� Hi. I have a problem making Conditional Columns work. Have a column with values from 0-100 and some blanks. I just want all the rows that contain a number to have text and the blanks to be empty. PowerBI won't accept making a null into a null somehow. Is there a workaround? Thanks in advance

You need to add the classes and remove them on user actions. The classes can be added with element.classList.add() and removed with element.classList.remove() Also the css properties are not set on the classes that you are trying to add. Run the snippet to see if this is what you want

const userprompts = document.querySelector("#prompts");
    const userstory = document.querySelector("#story");
    const usererror = document.querySelector("#error");

    const submit = document.querySelector("#submit");
    submit.addEventListener("click", completestory, false);

    const reset= document.querySelector("#reset");
    reset.addEventListener("click", resetPage, false);

    document.querySelector('#name').focus();

    const thename = document.querySelector("#name");
    const firstverb = document.querySelector("#firstverb");
    const firstnoun = document.querySelector("#firstnoun");
    const adjective = document.querySelector("#adjective");
    const secondnoun = document.querySelector("#secondnoun");
    const adverb = document.querySelector("#adverb");
    const place = document.querySelector("#place");
    const storyOutput = document.querySelector("#storyOutput");

    userprompts.classList.add("displayBlock");
    userstory.classList.add("displayNone");
    usererror.classList.add("displayNone");

    function checkStory() {

    }

    function completestory() {
      let finishedstory = "";
      finishedstory += "There once was a person named " + thename.value + ". ";
      finishedstory += "One day, " + thename.value + " was " + firstverb.value + " out in the "
      + firstnoun.value + ". ";
      finishedstory += "All of a sudden, " + thename.value + " saw a " + adjective.value +
      " dragon! " ;
      finishedstory += thename.value + " thought for a second and did the only thing that came to mind "
      + " and grabbed a " + secondnoun.value + ". " ;
      finishedstory += "With the " + secondnoun.value + " in hand, " + thename.value + " jumped up and " + adverb.value + " attacked the dragon.";
      finishedstory += " The dragon became very confused and left. Our hero returned to their ancestral home of " + place.value + " ." +  " The End?";

      storyOutput.innerHTML = finishedstory;

      userprompts.classList.add("displayNone");
      userstory.classList.add("displayBlock");
      usererror.classList.add("displayNone");
      userprompts.classList.remove("displayBlock");
    userstory.classList.remove("displayNone");
    usererror.classList.remove("displayBlock");
    }

    function resetPage() {
      userprompts.classList.add("displayBlock");
      story.classList.add("displayNone");
      error.classList.add("displayNone");
userprompts.classList.remove("displayNone");
    userstory.classList.remove("displayBlock");
    usererror.classList.remove("displayBlock");
      thename.value = "";
      firstverb.value = "";
      firstnoun.value = "";
      adjective.value = "";
      secondnoun.value = "";
      adverb.value = "";

      storyOutput.innerHTML = "";

      thename.focus();

    }
.displayBlock{
display: block;
}

.displayNone{
display: none;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <link rel="stylesheet" href="Mod3Layout.css">
    <meta charset="utf-8">
    <title>Sean's Mad Lib</title>
  </head>
  <body>
    <h1> Sean's Wacky Mad Lib</h1><hr>

    <div id="prompts">
      <h3>Please enter your prompts here</h3>
      <p>Enter a name here:
        <input id="name" type="text" placeholder="name">
        </p>
        <p>Enter a verb here:
          <input id="firstverb" type="text" placeholder="verb 1">
          </p>
          <p>Enter a noun here:
            <input id="firstnoun" type="text" placeholder="noun 1">
            </p>
            <p>Enter an adjective here:
              <input id="adjective" type="text" placeholder="adjective">
             </p>
             <p>Enter another noun here:
               <input id="secondnoun" type="text" placeholder="noun 2">
             </p>
             <p>Enter an adverb here:
               <input id="adverb" type="text" placeholder="adverb">
             </p>
             <p>Finally, Enter a place here:
               <input id="place" type="text" placeholder="place"
               </p><br>
             <button id="submit" type="button">Submit</button>
             <p id="error">You did not answer all the questions. Please try
               again</p>
      </div>
      <div id="story">
        <p>Let's see what you wrote.</p>
        <p id="storyOutput">Hello Dave</p>
        <button id="reset" type="button" name="Reset">Reset</button>
        </div>

Places it's tempting to use `display: none;`, but don't, it and don't want to think too hard about if the specificity value is strong enough. slideUp() , you'll have a display: none in the inline CSS to deal with. Yes, screen readers run JavaScript and yes, that's still a problem. It's not based on my deep and thorough understanding of screen readers and general accessibility. I found a solution. I almost went crazy. You wont believe how stupid is design EXCEL 2016. I dont know if on 2013 happen the same problem. Here is the solution. My Windows 10 and Excel 2016 are in English, but my regional setting are for Spanish (Venezuela), so my keyboard layout and regional setting are different than English.

Exceptions and debugging � Advanced R., Debugging is the art and science of fixing unexpected problems in your code. Printed output is not a condition, so you can't use any of the useful condition handling tools you'll learn about What function do you use to ignore errors in block of code? Usually, however, you'll have to think a bit more about the problem. Conditional statements help you to make a decision based on certain conditions. These conditions are specified by a set of conditional statements having boolean expressions which are evaluated to a boolean value true or false. There are following types of conditional statements in C. If statement; If-Else statement; Nested If-else statement

Making decisions in your code — conditionals, However, you need to be careful here — in this case, the second block of code is not controlled by the conditional statement, so it always runs,� Select column A. On the Home tab, click the arrow next to Conditional Formatting in the Styles group,and then click New Rule.. In the New Formatting Rule dialog box, click Use a formula to determine which cells to format.

Python Tutorial: Exception Handling, Introduction on Exception handling with try, except and finally. "file open error" and so on) which had occurred, the error handler can "fix" the problem The code, which harbours the risk of an exception, is embedded in a try block. It's possible to create "custom-made" exceptions: With the raise statement it's possible to� Conditional statements. This lesson introduces the Logic blocks such as ‘If…then’ and ‘If…then…else’. Students practice skills of creativity, problem

Comments
  • Is there an error? Does something not work? If so, what doesn't work? etc...
  • My userprompts should be on the screen when the page loads. Userstory and usererror should not. As it is now, they are all on the screen
  • I think you're trying to set the style display: block and display: none? Those aren't class names unless you have some custom CSS.
  • The OP isn't using jQuery.