Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Sentence is not printing on browser

I have to tried to examine and make correction repeatedly on my code but it's still not printing the sentence when I run the it on the browser. Everythings seems to right to me but have no idea why the 'para.textContent' part is not printing ? The following are my code :

<body>
    <label for="weather"> Select 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 ;

            switch (choice) {
                case 'sunny' :
                    para.textContent = 'It is a beautiful day today ! Let\'s go to the park, take a walk outside !';
                    break;

                case 'rainy'  :
                    para.textContent = 'It\'s rainy outside. Don\'t forget to bring an umbrella if you want to walk outside.;
                    break;   

                 case 'snowing' :
                    para.textContent = 'It\'s snowing outside. Just stay at home, sit by the window, sip your tea while reading book and watch outside.' ;
                    break;
                    
                 case '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.';
                    break;

                 default :
                    para.textContent = ''';   
            }
        }
</script>
</body>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You had not used quotes properly hence you were getting error. Try to use double quotes "" just to make the code more legibile.

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

select.addEventListener('change', setWeather);

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

  switch (choice) {
    case 'sunny':
      para.textContent = "It is a beautiful day today ! Let\'s go to the park, take a walk outside !";
      break;

    case 'rainy':
      para.textContent = "It\'s rainy outside. Don\'t forget to bring an umbrella if you want to walk outside.";
      break;

    case 'snowing':
      para.textContent = "It\'s snowing outside. Just stay at home, sit by the window, sip your tea while reading book and watch outside.";
      break;

    case '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.";
      break;

    default:
      para.textContent = '';   
  }
}
<body>
  <label for="weather"> Select 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>
</body>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!