i trying solve problem, function accepts string, in lowercase, , takes first letter , adds of string.
it not seem working.
var fir; function convert(str) { str = str.split(""); fir = str[0]; str = str.join(""); switch (fir) { case /[bcdfghjklmnpqrstvwxyz]/.test(fir): var ind = str.substr(1); str = ind + str[0]; break; } return str; }
if call convert("pig");
part of javascript should return "igp"
i think need asked - " function accepts string, in lowercase, , takes first letter , adds of string".
function convert(str) { str = str.substr(1) + str[0]; return str; } convert("pig");
if insistent on using have, have fixed here.
var fir; function convert(str) { str = str.split(""); fir = str[0]; str = str.join(""); switch (true) { case /[bcdfghjklmnpqrstvwxyz]/.test(fir): var ind = str.substr(1); str = ind + str[0]; break; } return str; } convert("pig");
the change have done changing switch(fir)
switch(true)
why switch case wasn't working.