I'm using inquirer.js
to create a simple prompt for a CLI script. I'm trying to set a variable value inside a switch statement then use this variariable inside an axios instance configuration.
I'm facing the problem that the variable will be always undefined, how I can set it correctly?
let url;
switch( answers.language ){
case 'Italian':
url = 'https://it.wikipedia.org/w/api.php';
break;
case 'English':
url = 'https://en.wikipedia.org/w/api.php';
break;
case 'Deutch':
url = 'https://de.wikipedia.org/w/api.php';
break;
}
axios({
url: url,
method: 'GET',
params: {
action: 'query',
list: 'search',
srsearch: answers.search,
format: 'json'
}
}).then( (response) => {
console.log(response);
console.log(response.data);
});
You need to add a default option in your switch case. for example: