I want to print an errormessage using javascript in certain cases. The string is german and the start depends on a variable called blfType
which can be "field", "line" or "block" and the string then would be "This field already has this prerequisite" if blfType
is field. I tried to do that similiar as I would do it in python:
alert("Das Feld"*(blfType == 'field') + "Die Zeile"*(blfType == 'line') + "Der Block"*(blfType == 'block')+" besitzt diese Vorraussetzung bereits");
But this would just print "NaN besitzt diese Vorraussetzung bereits"
. Is there any other way how I can do this in just one line or do I have to do create another Variable that takes the start of the sentence.
In this case I would do this in python like that:
const gerblfType = "Feld" if blfType === "field" else "Zeile" if blfType === "line" else "Block"
But this is also not working. Is there a smooth way in Javascript to not do it like that:
gerblfType = "Feld";
if(blfType == "line") gerblfType = "Zeile";
if(blfType == "block") gerblfType = "Block";
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment