Skip to content

Instantly share code, notes, and snippets.

@krogowsk531
Last active May 3, 2020 23:25
Show Gist options
  • Save krogowsk531/5babed217997b7bcf1642491db7c62e1 to your computer and use it in GitHub Desktop.
Save krogowsk531/5babed217997b7bcf1642491db7c62e1 to your computer and use it in GitHub Desktop.

Drink Conditionals

  if (old <= 13) {
    return 'drink toddy';
  } else if (old > 13 && old <18) {
    return 'drink coke';
  } else if (old > 17 && old <21) {
    return 'drink beer';
  } else {
    return 'drink whisky';
  }
};


//receives age as old parameter
//0-13 drink toddy
//14-17 drink coke
//18-20 drink beer
//21+ drink whiskey
//returns what they drink

Array Plus Array

  var addElements = 0
  for (var i = 0; i < arr1.length; i++) {
    addElements += arr1[i]
  }
  for (var j = 0; j < arr2.length; j++) {
    addElements += arr2[j]
  }
  return  addElements
};

//sum up each element inside of array1 using a for loop
//sum up each element inside of array2 using anot
//add array1 to array2
//return total

Find the Smallest Integer in an Array

  findSmallestInt(args) {
    var smallestNumber = args[0];
    for ( var i = 0; i < args.length; i++) {
      if (smallestNumber > args[i]) {
      var smallestNumber = args[i]
      console.log(smallestNumber)
      }
    }
    return smallestNumber
  }
}

//search for the smallest number in the args array
//working with numbers in an array
//use a for loop to search the values inside of the array
//create a variable outside of loop that is set to zero
//run the loop and use the variable set to zero to access the smallest integer in the array
//return the smallest integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment