QUESTION #1What would be logged to the console by the following block of code?let roles = "user,moderator";if (roles.includes("admin")) { console.log("user is an admin");} else if (roles.includes("moderator")) { console.log("user is a moderator");} else { console.log("user does not have any special role");};user is a moderatoruser is an adminuser does not have any special role
Question
QUESTION #1What would be logged to the console by the following block of code?let roles = "user,moderator";if (roles.includes("admin")) { console.log("user is an admin");} else if (roles.includes("moderator")) { console.log("user is a moderator");} else { console.log("user does not have any special role");};user is a moderatoruser is an adminuser does not have any special role
Solution
The output of the given block of code would be "user is a moderator".
Here's the step by step explanation:
-
The variable "roles" is defined and assigned the string "user,moderator".
-
The "if" statement checks if the string "roles" includes the substring "admin". It does not, so the code within this block is skipped.
-
The "else if" statement checks if the string "roles" includes the substring "moderator". It does, so "user is a moderator" is logged to the console.
-
The final "else" block is not executed because the condition of the "else if" statement was met.
So, the output is "user is a moderator".
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.