JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 7 Example 8 Function Returning Function

		
001function greetingTranslation(lang=''){
		
002	if(lang.toLowerCase() === 'greek'){
		
003		return function(name){
		
004			console.log('Geia sou '+name);
		
005		}
		
006	} else if(lang.toLowerCase() === 'spanish'){
		
007		return function(name){
		
008			console.log('Hola '+name);
		
009		}
		
010	} else { // return English
		
011	
		
012		return function(name){
		
013			console.log('Hello '+name);
		
014		}
		
015	}
		
016}
		
017window.onload = function(){
		
018	let englishHello = greetingTranslation(); //triggers else
		
019	let spanishHello  = greetingTranslation('SPANISH');
		
020	let greekHello    = greetingTranslation('Greek');
		
021	
		
022	
		
023	spanishHello('Toby');
		
024	greekHello('Toby');
		
025	englishHello('Toby');
		
026	
		
027	
		
028	greetingTranslation('english')('World');
		
029}