Custom input box and submit button

I added an input box and submit button separately onto the page.
What do I want to happen?
When the user types ‘krh’ into the input box and clicks on enter, they are supposed to go to the ‘krh’ page.

import wixLocation from 'wix-location';

$w.onReady(function () {
 // Write your JavaScript here
 const inputBox = $w('#input2');
 const pin = $w('#input2').value;

    inputBox.onKeyPress((event)=>{
 if(event.key === 'Enter'){
 if(pin === 'krh'){wixLocation.to('/krh');}
        }
    }
    )

}   
);

Your code needs some correction…

$w.onReady(function () {
 // Write your JavaScript here
 //const inputBox = $w('#input2');
 //const pin = $w('#input2').value;

    $w('#input2').onKeyPress((event)=>{
 if(event.key === 'Enter'){
 if($w('#input2').value === 'krh'){wixLocation.to(`/krh´);}
        }
    });
    

});

const →
The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned.

Thanks Ajit. It is now working!

Got the answer