Totally new, is there something wrong with this switch script for color changes?

I am still learning on my own with tutorials so any knowledge and direction would be amazing. The lesson I was going over was meant to teach using switches to change the color of an object. However, nothing I do makes the object respond as it did in the video. Is there something my script is missing for that simple purpose? I am able to run it without being met with compiling errors or console problems so I am lost.

Here is what I have got, any suggestions?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ColorChange : MonoBehaviour
{

public GameObject cube;
private int _nextColor;
// Start is called before the first frame update
void Start()
{
    _nextColor = 0;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Alpha1))
    {
        _nextColor = 0;
    }

    if (Input.GetKeyDown(KeyCode.Alpha2))
    {
        _nextColor = 1;
    }

    if (Input.GetKeyDown(KeyCode.Alpha3))
    {
        _nextColor = 2;
    }

    if (Input.GetKeyDown(KeyCode.Alpha4))
    {
        _nextColor = 3;
    }

    switch (_nextColor)
    {
        case 0:
            cube.GetComponent<Renderer>().material.color = Color.blue;
            break;
        case 1:
            cube.GetComponent<Renderer>().material.color = Color.red;
            break;
        case 2:
            cube.GetComponent<Renderer>().material.color = Color.green;
            break;
        case 3:
            cube.GetComponent<Renderer>().material.color = Color.black;
            break;
           
    }
}

}

When I copied the code I was able to make the code work perfectly without any changes.

Make sure that the script is actually attached to a gameObject. Other than that, I can’t think of any reason why this wouldn’t be working. Can you provide more details about the cube and the object the script is attached to?