Change panels color when click button

hi i want to Change panel color when i click button how to do this, i test the code
https://forum.unity.com/threads/changing-the-color-of-a-panel-in-code.286153/
public Image panel;

 // Use this for initialization
 void Start () {
     panel = GetComponent<Image>();
 }

 // Update is called once per frame
 void Update () {
     

     panel.color = GetRandomColor();

 }
 Color GetRandomColor(){
     
     return new Color(Random.value, Random.value, Random.value);
 }

}
but i get null reference and i don’t know how to attach it to my panel

@cliffmlimwa

Make a script called RandomColorforpannel and past this in it.

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

public class RandomColorforpannel : MonoBehaviour {

Image panel;

// Use this for initialization
void Start () {
    panel = GetComponent<Image> ();
}

public void Doit () 
{
    panel.color =GetRandomColor();
} 

  Color GetRandomColor()
{
    return new Color (Random.value, Random.value, Random.value);
}

}