Mixed Messages, review?

My first ever software?!

I know i still will need to do this few more time before i completely understand! Any feedback for critiqe would be warranted!

  • pick random number for objects arrays
  • made variable that will hold the arrays data
  • iterated through the arrays (declared order?)
  • conditionals with the random message being pushed
  • will make better
function generateRandomNumber(num) {
    // Gets # from 0 -> num - 1
    return Math.floor(Math.random() * num)
  }
  
  
  
  const ixAmMessages = {
    excuse: ['tried to catch you earlier!', 'hey, dont worry about yesterday', 'sorry i slept in late, just wanted to say'],
    IxAM: ['YOUxARE', 'WExARE'],
    motivated: ['Better Than That', 'Learning', 'Not Giving Up!', 'Going to Work Harder', 'Going to the Gym'],
    attractive: [' You are so freakin Beautiful', 'you are hot and Handsome', ' dang! Looking Great!', ' are you Losing Weight?', 'taking care of yourself'],
  }
  // puts the 'talk' in an array
  let ixAmTalk = []
  
  //! add another array to the object
  // iterate through arrays
  for (let talk in ixAmMessages) {
    let order = generateRandomNumber(ixAmMessages[talk].length)
    switch (talk) {
      case 'excuse':
      case 'IxAM':
      case 'motivated':
      case 'attactive':
        ixAmTalk.push(`'${ixAmMessages[talk][order]}'!`)
        break
              default:
        ixAmTalk.push('and i oop! hold up!')
    }
  }

  //  random indices for each property
  const randomExcuseIndex = Math.floor(Math.random() * ixAmMessages.excuse.length);
  const randomIxAMIndex = Math.floor(Math.random() * ixAmMessages.IxAM.length);
  const randomMotivatedIndex = Math.floor(Math.random() * ixAmMessages.motivated.length);
  const randomAttractiveIndex = Math.floor(Math.random() * ixAmMessages.attractive.length);
  
  // random items from each property
  const randomExcuseItem = ixAmMessages.excuse[randomExcuseIndex];
  const randomIxAMItem = ixAmMessages.IxAM[randomIxAMIndex];
  const randomMotivatedItem = ixAmMessages.motivated[randomMotivatedIndex];
  const randomAttractiveItem = ixAmMessages.attractive[randomAttractiveIndex];
  //? make flow better
  //  combined message
  const combinedMessage = `${randomExcuseItem} ${randomIxAMItem} ${randomMotivatedItem} and ${randomAttractiveItem}`;
  
  // Log the combined message to the console
  console.log(combinedMessage);

When posting your project for review, please be sure to include the following:

  • Your review of the Project. Was it easy, difficult, just right?
  • An estimate of how long it took you to complete
  • The link to your code repo

We hope you enjoyed this project!

the generateRandomNumber function didn’t seem to be used alot. You could make it return an item from an array instead of just a number, like this:

const excuse = ['tried to catch you earlier!', 'hey, dont worry about yesterday', 'sorry i slept in late, just wanted to say']; function returnRandomItemFromArray(array) { // Gets # from 0 -> num - 1 let index = Math.floor(Math.random() * array.length) return array[index] } console.log(returnRandomItemFromArray(excuse))

This way you can work with different sized array’s and you take a step out of your code elsewhere. FOR EXAMPLE you would return “tried to catch you earlier” rather than just “0”.

I like what you did with the switch to change the order of what you say, not just the individual items. If you are okay with “ixAmTalk” including multiple instances of the different categories, then I think it’s working as intended!

Also I’m impressed you used an object!

I think i may have screwed that one over, i assumed i needed the randomNumber function to sort of keep the order of how it was returned, however i wanted it to spit out randoms messages every time it was run. maybe i over thought it. my first ever, your feedback gave me a smack in the back of the head and a pat on the back, i have to appreciate more!