samedi 26 septembre 2015

Javascript use if statement in variable

Hello stackoverflow community,

I'm trying to create a variable through an if statement and other variables but it doesn't work. If anyone could help me i would really appreciate it.

This is my code to create the returntouser variable

function userinput() {
  return returntouser = metaTitle + "\n" +  metaDescription + "\n" + metaKeywords;
}

Now i'm trying to make an if function out of the "metaTitle" variable. If an user don't write anyting in the textform, the "metaTitle" variable will not be added to the "returntouser" variable.

function userinput() {
  return returntouser = if (document.getElementById("userinputTitle").length > 0) { return metaTitle } + "\n" +  metaDescription + "\n" + metaKeywords;
}

Can someone tell me how i can add this if function to either add the "metaTitle" variable to the "returntouser" variable or not

Aucun commentaire:

Enregistrer un commentaire