lundi 19 août 2019

combining switch loops to concatenate the result

Please forgive my noob-ness.

So, i figured out how to create two separate switch loops, in order to access two separate values. My trouble now, is that I don't know how to write a function that would allow me to concatenate the results of the two switch values.

var select = document.getElementById('weather');
var para = document.getElementById('alf');
var door = document.getElementById('dance');
var mort = document.getElementById('tim');
document.getElementById('weather').addEventListener('change', 
setWeather);
document.getElementById('dance').addEventListener('change', 
setDance);



function setWeather() {
  var choice = this.value;

  switch(choice) {
   case 'sunny':
     para.textContent = "fly me to the Moon";
     break;
   case 'rainy':
     para.textContent = "let me sail amongst the stars";
     break;
   case 'snowy':
     para.textContent = "life on Jupiter and Mars";
     break;
default:
  para.textContent = "";
 }
 }
  function setDance() {
  var art = this.value;

switch(art) {
  case 'hail':
    mort.textContent = "in other words";
    break;
  case 'rail':
    mort.textContent = "darling kiss me";
    break;
  case 'cat':
    mort.textContent = "please be true";
    break;
  default:
    mort.textContent = "";
 }
 }

function result() {
  weatherVal = weather.value;
  danceVal = dance.value;
  para.textContent = weatherVal + danceVal;
}

I tried to use the above code "function result()" to write the function to create the concatenation, but no success. I feel like the answer is right in front of me, but I'm just not quite sure what's going on.

Aucun commentaire:

Enregistrer un commentaire