javascript - Switch statement automatically performing cases without meeting case requirements? -
i made switch statement , begun work until began adding more code it.. take look:
var txt; var begin = 'some text'; var briefbegin = 'some text'; var started = false; var input = function () { switch (true) { case 'start' && !started: txt = begin; started = true; break; case 'start brief' && !started: txt = bbegin; started = true; break; default: txt = "some text." } $('.output1').text(txt); };
i called down here...
var teext; $(".submit").click(function() { teext = $('.inputt').val(); input(teext); console.log(teext); }); $(".inputt").keyup(function(event){ if(event.keycode == 13){ $(".submit").click(); } });
so whenever type in input field (under class ".inputt") whether fits case or not, automatically prints every case top bottom. appreciated :d thanks
i suspect want. compares parameter it's given strings in case
statements.
var input = function (text) { switch (true) { case text == 'start' && !started: txt = begin; started = true; break; case text == 'start brief' && !started: txt = bbegin; started = true; break; default: txt = "some text." } $('.output1').text(txt); };
Comments
Post a Comment