So, there are several ways to answer this. This is not exactly shorter, but your intentions may be more obvious and direct with switch rather than if s:
switch (number) { case "0": degrees = "-160"; break; case "1": degrees = "-158"; break; ... }
But for this type, the lookup table can be more understandable and concise:
var degreesLookupTable = { "0": "-160", "1": "-158", "2": "-156", "3": "-154", "4": "-152", "5": "-150", "6": "-148", "7": "-146", "8": "-144", "9": "-142", "10": "-140" }; if (number in degreesLookupTable) degrees = degreesLookupTable[number] else throw "Number not found in degree map!"
See the “Search Tables” section here for more information.
Thirdly, there seems to be a direct mathematical relationship between number and degrees . Maybe just write a function to calculate degrees directly based on the value of number ?
source share