How do I change 2d motor speed from a script?

Here is my code so far

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Paddle : MonoBehaviour {
     private Rigidbody2D rb2d;
     private HingeJoint2D jointRef;
     private JointMotor2D motorRef;
     public float speed = -100;
     // Use this for initialization
     void Start () {
         rb2d = GetComponent<Rigidbody2D> ();
         jointRef = GetComponent<HingeJoint2D> ();
         motorRef = jointRef.motor;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown ("left"))
             motorRef.motorSpeed = speed;
     }
 
     void FixedUpdate ()
     {
         
         
     }
 }
  1. Create a new motor.
  2. Set the values.
  3. Assign the motor to the
    hingjoint.motor.

JointMotor2D motorRef = new JointMotor2D();
//Set values of motor
jointRef.motor = motorRef;


This worked for me.