# Javascript if/else

**URL:** <https://forum.freecodecamp.org/t/javascript-if-else/448414>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 25, 2021, 4:43pm UTC](https://forum.freecodecamp.org/t/javascript-if-else/448414 "2021-02-25T16:43:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjsnh](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jjsnh](https://forum.freecodecamp.org/u/jjsnh)\
**Post date:** [February 25, 2021, 4:43pm UTC](https://forum.freecodecamp.org/t/javascript-if-else/448414/1 "2021-02-25T16:43:52Z")

</div>

The following script works fine (i am not familiar with Javascript). I wish to change the para.textcontent to display a form (paypal button). if I inset the form in the para.textconten field it does not work. Any help? I have shown the button code below the script.

```auto
<tr>
           <td>
                      <label for="weather">Select the weather type today: </label>
                      <select id="weather">
                          <option value="">--Make a choice--</option>
                              <option value="sunny">Sunny</option>
                              <option value="rainy">Rainy</option>
                              <option value="snowing">Snowing</option>
                              <option value="overcast">Overcast</option>
                       </select>

                       <p></p>

                       <script>
                              const select = document.querySelector('select');
                              const para = document.querySelector('p');

                              select.addEventListener('change', setWeather);

                              function setWeather() {
                                  const choice = select.value;

                                 if (choice === 'sunny') {
                                     para.textContent = 'It is nice and sunny outside today. Wear shorts! Go to the beach, or the park, and get an ice cream.';
                                     } else if (choice === 'rainy') {
                                      para.textContent = 'Rain is falling outside; take a rain coat and an umbrella, and don\'t stay out for too long.';
                                     } else if (choice === 'snowing') {
                                      para.textContent = 'The snow is coming down — it is freezing! Best to stay in with a cup of hot chocolate, or go build a snowman.';
                                     } else if (choice === 'overcast') {
                                     para.textContent = 'It isn\'t raining, but the sky is grey and gloomy; it could turn any minute, so take a rain coat just in case.';
                                     } else {
                                       para.textContent = '';
                                     }
                                  }
                             </script>

                        </td>
                    </tr>

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="DJUTWCWH7R9FJ" />
<table summary=''>
<tr><td><input type="hidden" name="on0" value="Rack Size" /></td></tr><tr><td><select name="os0">
	<option value="Jr. Enlisted">Jr. Enlisted &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$43.99 USD</option>
	<option value="Sr. Enlisted">Sr. Enlisted &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$45.99 USD</option>
	<option value="Stateroom">Stateroom &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$47.99 USD</option>
	<option value="Submarine Crew">Submarine Crew &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$43.99 USD</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD" />
<br style='line-height: 10px' />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" style="width:100px; height:25px;" name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>

```

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [February 25, 2021, 4:48pm UTC](https://forum.freecodecamp.org/t/javascript-if-else/448414/2 "2021-02-25T16:48:06Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![jjsnh](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jjsnh](https://forum.freecodecamp.org/u/jjsnh)\
**Post date:** [February 25, 2021, 5:22pm UTC](https://forum.freecodecamp.org/t/javascript-if-else/448414/3 "2021-02-25T17:22:06Z")

</div>

OK, but how do I insert the form code into the else statement?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 27, 2021, 5:22am UTC](https://forum.freecodecamp.org/t/javascript-if-else/448414/4 "2021-08-27T05:22:52Z")

</div>

Closed on August 27, 2021, 5:22am UTC

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