Messy code and issues in it

Im making a program like the amazon echo using p5.speech. My code is not only messy and confusing but every time it hears speech it runs the else instead of what is supposed to happen

let carl = 'hey carl';
var value = 220;
let time = 'what time is it';

function setup() {
  createCanvas(400, 400);
  let hours  = hour();
let min = minute();
  
   if (hours<=12){
    let hr = hour;
    }else{
    let hr = hour%12;
    }

}

function draw() {
  background(value);
  textSize(50);
  //Fill();
  strokeWeight(4);
  text("Hello I am Carl", 35,200);
  textSize(25);

 text("Click to start", 130, 300);
  rect(400,400,0,0);
}

  function mousePressed(){

if(value===220){
value = 0;
  carlBegins();
   } }

function carlBegins() {
let lang = navigator.language || 'en-US';
let speechRec = new p5.SpeechRec(lang, gotSpeech)
speechRec.continuous = true;
speechRec.start();
  let heyCarl = speechRec
  
  function gotSpeech() {
  if (speechRec == carl){
  startLis();
    var myVoice = new p5.Speech();
    myVoice.speak('yes?',hasSpoken);
  }else{
  console.log('oops');
  }
  }
  function startLis() {
 
console.log('yes?')

    times();
    }
    function hasSpoken() {
      if(heyCarl===time){
      
    myVoice.speak(hour);
      myVoice.speak(minute);
      }
      }
}

Can you please edit your post to format your code?

Also, can you please try to be more specific? Which if statement are you having trouble with? Can you narrow the problem down to a simpler example?

this is the issue if statement it keeps returning oops instead of what it is supposed to

pls format your code using the
Preformatted text block:

</>

( in both of your posts )

pls edit your TITLE

Messy code and issues in it

to tell the average reader what it is about

to understand why your IF not work, i suggest
you print out!

function gotSpeech() {
  console.log("speechRec: " +speechRec+" carl: "+carl)
}

to see whats inside before you make a compare
you might want to use:
speechRec.resultString
instead

2 Likes