1
I am doing some exercises of js and I would like to know if my function is correct!
1) Write a function that checks whether the past skill vector has the "Javascript" ability and returns a true/false boolean if it exists or not.
function Habilidade(skill){
if(skill == 'javascript'){
console.log('Você sabe javascript');
} else if(skill == 'reactjs'){
console.log('Você sabe reactjs');
} else if(skill == 'React native'){
console.log('Você sabe React native');
} else{
console.log('Você não sabe nenhuma das linguagens');
}
}
var resultado = Habilidade('javascript');
var skill = ['javascript', 'reactjs', 'React native'];
By the description of the problem, the function does not do what it says.
– Maniero
Your function does not receive the array in your example, and even if it did, it would not work the right way, besides, it does not return a boolean value
– Denis Rudnei de Souza
You will need to have the function go through all the values of the array passed as parameter in the function, based on this you compare if there is the value, if there is the value requested, you return true, otherwise false
– Denis Rudnei de Souza
Denis could you explain me in more detail? Thank you.
– Gregolly França
"My function is correct" - Could improve your question by adding part of the doubt that is in the content.
– Fabiano Monteiro
if you want to do one more you can use regex and check if a phrase has a certain word or expression
– Costamilam