A nearly soulless rendition of the Drum Machine challenge

A nearly soulless rendition of the Drum Machine challenge
0

#1

#2

In the following method, e is not an event (it is a string), so you can delete the e.preventDefault, because it is not doing anything. You do not need a switch statement at all. The variable e is a string which you can use with document.getElementById. However, you really should be using refs and not directly accessing the DOM as you are here.

playSound(e){
    e.preventDefault;
  switch(e){
    case 'Q':
      document.getElementById('Q').play();
      break;
    case 'W':
      document.getElementById('W').play();
      break;
    case 'E':
      document.getElementById('E').play();
      break;
    case 'A':
      document.getElementById('A').play();
      break;
    case 'S':
      document.getElementById('S').play();
      break;
    case 'D':
      document.getElementById('D').play();
      break;
    case 'Z':
      document.getElementById('Z').play();
      break;
    case 'X':
      document.getElementById('X').play();
      break;
    case 'C':
      document.getElementById('C').play();
      break;
    default:   document.getElementById('WrongButton').play();      
      break;
  }

    this.setState({ lastButtonPushed: e});
  }


#3

Thanks, sir. I shed the playSound switch. That puts my total code at 100 lines.

I don’t follow the refs feedback. I’ll review the lessons for an example over the next few days.