function getReturnCodeUsingKey(keyFromUserInput)
{
var GardinerToUnicodeCodePoint = {
"A1" :"995328",
"A1A" :"995329",
"A1B" :"995330",
"A1C" :"etc"
};
returnVal = GardinerToUnicodeCodePoint[keyFromUserInput];
return returnVal ? returnVal : "error: no match found";
}
Передайте эту функцию вашему string input
от пользователя, и он вернет то, что вы хотите, я думаю.
Итак, ваше полное решение будет выглядеть так:
$(document).ready(function() {
$("#convert").click(function(){
var userInput = $("#userInput").val(); /*for example 'A1'*/
// a call to our new function keeping responsibilities seperated
return getReturnCodeUsingKey(userInput);
});
});
function getReturnCodeUsingKey(keyFromUserInput)
{
var GardinerToUnicodeCodePoint = {
"A1" :"995328",
"A1A" :"995329",
"A1B" :"995330",
"A1C" :"995331",
"A2" :"995332",
"A2A" :"995333",
"A3" :"995334",
"A3A" :"995335",
"A3B" :"995336",
"A4" :"995337",
"A4A" :"995338",
"A4B" :"995339",
"A4C" :"995340",
"A4D" :"995341",
"A4E" :"995342",
"A5" :"995343",
"A5A" :"995344",
"A5B" :"995345",
"A5C" :"995346",
"A6" :"995347",
};
// set a variable to hold the return of the object query
returnVal = GardinerToUnicodeCodePoint[keyFromUserInput];
//return valid value from object, or string if undefined
return returnVal ? returnVal : "error: no match found";
}