1. Write a loop that calculates 12-factorial

set result and n to 0

n <- 0
result <- 1

while (n < 12){
  n <- n + 1
  result <- result * (n)
}

result
## [1] 479001600

verify n ends as 12

n
## [1] 12

calculate expected result

expected <- 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12

check result

result == expected
## [1] TRUE

2. Create a numeric vectorsequence from 20 to 50 by 5

v <- seq(20,50,5)
v
## [1] 20 25 30 35 40 45 50

3. Create “factorial” function with 3 inputs

factorial <- function(a,b,c){
  
  j1 <- b ^ 2
  j2 <- 4 * a * c
  if (j1 < j2){return(cat("I\'m sorry, Dave, but I can\'t do that (it\'ll return an NA 
because b-sqared minus 4ac will result in a negative and the
square root would be i)"))}
  j3 <- sqrt(j1 - j2)
  j4 <- 2 * a
  k1 <- (a + j3) / j4
  k2 <- (a - j3) / j4
  cat("the solutions to your quadratic equation are ")
  cat(k1)
  cat(" and ")
  cat(k2)
}

check with variables that should not trigger n/a

factorial(-2,60,800)
## the solutions to your quadratic equation are -24.5 and 25.5

check with variables that should trigger n/a

factorial(3,2,1)
## I'm sorry, Dave, but I can't do that (it'll return an NA 
## because b-sqared minus 4ac will result in a negative and the
## square root would be i)