Jump to content

Hello All, does anyone have any idea why this doesn't work? I'm new to javascript and having a bit of trouble.

<select id="myInput" name="Symptoms">
  <option value="fears">Unshakable Feelings of Dread, Apprehension and Irrational Fears</option>
  <option value="fastHeart">Heart Palpitations</option>
  <option value="abnormalBreathing">Difficulty Breathing or Hyperventilating</option>
  <option value="dizziness">Dizziness or Feeling Faint</option>
  <option value="chestPain">Chest Pains, Tightness and other Symptoms like a Heart Attack</option>
  <option value="concentrate">Inability to Concentrate</option>
  <option value="insominia">Insominia</option>
  <option value="chills">Chills & Hot Flashes</option>
  <option value="dryMouth">Dry Mouth</option>
  <option value="doom">Sense of Impending Doom</option>
  <option value="stomach">Stomach Cramps, Diarrhea, Nausea and other Intestinal Problems</option>
  <option value="clamminess">Claminess</option>
  <option value="muscle">Muscle Tension, Aches & Pains</option>
  <option value="exhaustion">Exhaustion</option>
  <option value="pins">Pins & Needles</option>
  <option value="irritability">Irritability</option>
  <option value="sweating">Excessive Sweating</option>
  <option value="depersonalisation">Feelings of Depsonalisation or Unreality</option>
  <option value="headaches">Headaches</option>
  <option value="memory">Memory Problems</option>
  <option value="other">Other</option>
</select>
<button onclick="checkFruit()">Check Symptoms</button>
<p id="demo"></p>

<script>
function checkFruit() {
  var text;
  var symptoms = document.getElementById("myInput").value;

  switch(symptoms) {
    case "fears";
      text = "Unshakable Feelings of Dread, Apprehension and Irrational Fears are some of the most common anxiety symptoms and will often be followed by an acute period of anxiety when the preceived fears come to pass. These can be countered by relaxing.";
      break;
	  
    case "fastHeart":
      text = "Heart Palpitations are a very common anxiety symptom and occur when your body goes in to fight or flight mode. This often occurs during a panic attack and at the same time as hyperventiliation. We recommend that you try breathing crisis message for this.";
      break;
	  
    case "abnormalBreathing":
      text = "These are very common symptoms and our related to the fight or flight mechanism of the human body which is there to help you get ouot of danger. We recommend that you try breathing crisis message for this.";
      break;
	  
    case "dizziness":
      text = "Dizziness and Feeling Faint are often caused by improper levels of oxygen and carbon dioxide in your body. This is a common symptom and we recommend that you try breathing crisis message for this.";
      break;
	  
    case "chestPain":
      text = "Chest pain and chest tightness are caused when the muscles around the chet contract and stay in that position. The body often contracts a muscle when a person is tense. We suggest using the muscle relaxation for these symptoms.";
      break;

    case "concentrate":
      text = "The Inability to Concentrate symptom of anxiety is due to having so much of your available thinking resources being taken up by the anxiety that you are unable to devote the time in your head needed to another task. This is quite a common symptom and the best way to to distract yourself from those thoughts for a time. You can use both the crisis message and the relaxation technique for this.";
      break;
	  
	case "insominia":
      text = "Insominia is often related to the inability to concentrate in the fact it is generally being so full of anxiety that you cannot switch off from the anxiety and it's thoughts. The best thing you can do for insominia on your own is to use the muscle relaxation before you go to bed. You can do this as many times as necessary to fall asleep.";
      break;
	  
    case "chills":
      text = "Chills and hot flashes are similar in the face they are funcationally to do with vasodialation of the lood vessels. This is a normal thing the body does when it gets hot or is expecting to get hot due to exercise. So this would occur during the fight or flight mechanism, there because anxiety can trigger that you will experience these symptoms. You can try the muscle relaxation for this symptom but you can also just wait this out.";
      break;

    case "dryMouth":
      text = "Dry Mouth is a common symptom of anxiety and is caused by the body reducing water loss to feed the necessary parts fo the body during a fight or flight situation. To help with this you can drink more water and use the muscle relaxation technique.";
      break;
	  
	case "doom":
      text = "A sense of impending doom is common to anxiety. The sense that soemthing is going to happen. Often this means mroe anxiety is going to happen. Th best thing you can do is to try the muscle relaxation technique.";
      break;
	  
    case "stomach":
      text = "Gastro-intestinal problems are common with anxiety. Stress and anxiety can often cause the stomach to churn more than normal causing all types of problems. The best thing to do is take remedies for the individual problems as necessarya nd try to relax.";
      break;

    case "clamminess":
      text = "While stress and anxiety can often brin you down in such a way that it can cause cold like symptoms clamminess can also be caused by the same vasodialation functions as the chills. Try to relax when this happens and if you are coming down with a cold or other illness make sure you take the time to look after youself.";
      break;
	  
	case "muscle":
      text = "Muscle tension, aches and pains are all caused by the tensing of the individual muscles. This when it goes on for too long causes pain and then aches when it releases. The best way to combat it is to use the mucle relaxation technique to relax those muscles.";
      break;
	  
    case "exhaustion":
      text = "Anxiety can be exhausting, make sure you get enough sleep and rest. You will need more than a well person.";
      break;

    case "pins":
      text = "Pins \& needles can be casued by muscle tension. Relaxation is the best way to help this common symptom.";
      break;
	  
	case "irritability;":
      text = "Being scared can make people irritable. Anxiety is also being scared on a longer term basis and can also make you irritable. The opposite of anxious is being relaxed so a relaxation technique can help you here.";
      break;
	  
    case "sweating;":
      text = "When running or exercising you sweat. When your anxious your body reacts with the same sort of processes, so you increase your body temperature, increase energy production and release adrenaline. This causes an increase in heat so you sweat.";
      break;

    case "depersonalisation":
      text = "depersonalisation is best described as feeling like you aren't there or not connected to your body. This sensation will pass in it's own time, but the more you worry about it and focus on ti the more it will continue so any form of distraction will help you here.";
      break;
	  
	case "headaches":
      text = "Anxiety or stress headaches are common with anxiety and come on when you need to relax. A Muscle relaxation will help you reduce your headaches, along with taking necessary pain killers.";
      break;
	  
    case "memory":
      text = "Memory problems come on when you lack the ability to concentrate. If you forget where your keys are you weren't concentrating when you put them down. So this happens because you are full of anxiety and anxious thoughts. You can help those using a relaxation technique and distraction.";
      break;
	  
    default:
      text = "There are many other anxiety symptoms not included in this checker so please send suggestions to head office for more inclusions.";
  }
  document.getElementById("demo").innerHTML = text;
}
</script>

 

Link to comment
https://linustechtips.com/topic/636732-and-a-javascript-switch/
Share on other sites

Link to post
Share on other sites

Well it's saying that checkFruit is not defined. but as far as I know it's defined in the script underneath. and a variable that's declared text was unexpected. text is added to later in the code.

 

EDIT: managed to fix it. Thanks for the help matzeesch.

Link to comment
https://linustechtips.com/topic/636732-and-a-javascript-switch/#findComment-8216812
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×