Category : string

I think my question (above) is too broad. Let me try to explain here… Say I have 5 departments in a string: "Accounting ResearchDevelopment **InformationTech** System FrontOffice" and I have another string like this: "John is in **InformationTech** department" The value is InformationTech because this value matches in two strings. How do I get a ..

Read more

To clarify the situation, I conducted a simple test, and below is a runnable code snippet: function test() { const str = ‘abcd’; alert(Array.prototype.reduce.call(str, (result, _, i, _str) => { if(!i) result.push(`str type: ${typeof str}`); else if(i === 1) result.push(`_str type: ${typeof _str}`); else if(i === 2) result.push(`_str === str: ${_str === str}`); else result.push(`str: ..

Read more

let studentScore=90 let totalPossibleScore let gradeMessage = function(studentScore,totalPossibleScore=100){ let finalGradePercent = (studentScore/totalPossibleScore)*100 if (finalGradePercent>=90){ let letterGrade=’A’ return letterGrade } else if (finalGradePercent>=80) { let letterGrade=’B’ return letterGrade } else if (finalGradePercent>=70) { let letterGrade=’C’ return letterGrade } else if (finalGradePercent>=60) { let letterGrade=’D’ return letterGrade } else { let letterGrade=’F’ return letterGrade } } let ..

Read more

I need a function that takes a characters array and returns the same array but reversed and without the "*" character. I have tried a lot of codes without success. This was my last attempt (sorry if doesn’t have sense, I am learning JS) function laClaveSecreta(carac){ let new_str=[]; for(i=0;i<carac.length;i++){ if(carac[i]==="*"){ new_str=new_str.push(carac.replace(/[*s]/g, ”)); } return new_str.reverse(); ..

Read more

I have this piece of code and for some reason the template literal won’t recognize the space between lines. function requestCredit () { // Moves slide. $("#simulator-form-response").attr("class", "hiddenElement"); $("#contact-form").attr("class", "activeElement"); // Takes simulator form values and prints them in a message. let message = $("#creditQuery-data") message.text("") // Template literal message.text( `Tipo de crédito: ${creditType} Monto: ..

Read more