Something Like that:
Function factory
For that you need to create first html code.
JS
function makeGreeting(lang){ return function(firstname, lastname){ if(lang === 'en'){ document.write('Hello ' + firstname + ' ' + lastname); } if(lang === 'es'){ document.write('Hola ' + firstname + ' ' + lastname); } } } var greetEnglish = makeGreeting('en'); var greetSpanish = makeGreeting('es'); greetEnglish('John', 'Doa'); document.write('
'); greetSpanish('John', 'Doa');
[codepen_embed height=”265″ theme_id=”0″ slug_hash=”ZJvxrV” default_tab=”result” user=”pradeepanvi”]See the Pen Function factory in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]
Now you can see
Hello John Doa
Hola John Doa