Question: I have created a function day\_of\_week(dayy) and used switch-case statements in function.

```
function day_of_week(dayy) {
    var result;
    switch (dayy) {
        case 1:
            result = "monday";    
        case 2:
            result = "Tuesday";    
        case 3:
            result = "wednesday";    
        case 4:
            result = "thursday";    
        case 5:
            result = "friday";    
        case 6:
            result = "saturday";    
        case 7:
            result = "sunday";    
        default:
            result = "No day";
    }
    document.write(result);
}

document.getElementById("switch").innerHTML = day_of_week(1);
document.getElementById("switch").innerHTML = day_of_week(2);

```

Actually in switch-case statements if there is no "break" the code should execute randomly. But here when I declared variable called result and assigned the case values to it without "break". So, the code should execute all the cases randomly without any break. But, here the variable is under the instance of
redeclaring the value and executing the last case.
I am unable to know my mistake whether it is in declaring variable or using switch-case statements and all under the instance of function.
please help...

Answer: 
There is no break statement in your code. I hope this will work for you.

```
    <!DOCTYPE html>
<html>
<head>
<script>
function day_of_week(dayy){
   var result;
    switch(dayy){
      case 1: result = "Monday";
                         break;

        case 2: result = "Tuesday";
                          break;

        case 3: result = "wednesday";
                          break;

        case 4: result = "Thursday";
                          break;

        case 5: result = "Friday";
                          break;

        case 6: result = "Saturday";
                          break;

        case 7: result = "Sunday";
                          break;

        default: result = "No day";
   }
   document.write(result);

}
document.getElementById("switch").innerHTML = day_of_week(2);

</script>

</head>
<body>
</body>
</html>

```
I would do something like this to get a random day:

```
function getDay() {
    const days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];

    return days[Math.floor(Math.random() * 7)];
}

```