Hi! I am facing this problem while creating my own function "Error: unexpected '}' in " }" "

I have faced this problem many times: Error: unexpected '}' in " }" but do not know how to solve it. Take a look below

This is the code that I typed in:

ownfunc <- function(x, t, l, m){
hardik <- paste(x, t, l, m)
if(x > 6){
if(x < t < l < m){
print(seq(from = x, to = m, by = 17))
cat("The second number is", t, "and the third number is", l)
}else{
print("The x input should be smaller than the m input")
}
}else{
print("Pls type a number greater than 6")
}
}

While the console is displaying:

}
Error: unexpected '}' in " }"
}
Error: unexpected '}' in "}"

Pls someone tell me what is wrong with the code, thnx in advance

I think that x < t < l < m is not allowed. Try this

ownfunc <- function(x, t, l, m){
  hardik <- paste(x, t, l, m)
  if(x > 6){
    if(x < t & t < l & l < m){
      print(seq(from = x, to = m, by = 17))
      cat("The second number is", t, "and the third number is", l)
    }else{
      print("The x input should be smaller than the m input")
    }
  }else{
    print("Pls type a number greater than 6")
  }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Thankyou so much, it works like butter now :+1: