JavaScript - Division Of Words
Hi
Someone know any script for division of words into syllables? Regards stickers Similar TutorialsOut of curiosity: if I put that in address bar: Code: javascript: 128/1.618033988749894 that is ok, but what is calculated in this case ? Code: javascript: 128/1,618033988749894 Ok, im not going to show the whole code, for various reason but what I do display should be enough I am creating a program that will ask you how many people are on board the ship, how many people can fit in a lifeboat and how many lifeboats you have... The program will then calculate the minimum amount of lifeboats you will need to get everyone safely off board.... Heres my problem....Say it you input there are 800 people on board and only 90 people can fit per lifeboat, so you got 800/90 = 8.88 But you can't have it display as 8.88 because you can't have .88 lifeboats lol So instead of a double you make it an int, so it equals 8.... but you don't want it to equal 8 because then you'd be .88 lifeboats short, you want it to equal 9 so this is where IM truly stumped Heres a sample code of what I have Code: int minLb = peopleNumber/peoplePerLifeboat; System.out.println("A minimum of " + minLb + " lifeboats are required to rescue everyone on board."); And a sample of what it produces "Number of people on board the hg:800 Maximum number of people per lifeboat:90 Number of lifeboats that are available on the hg:7 Here are the results... A minimum of 8 lifeboats are required to rescue everyone on board. any help is appreciated Frustrated by the fact that you don't have the integer division operator in JavaScript? Here's a surprisingly little known method: parseInt(19/4) = 4 Now when a VBguru or vbscripter says "ha ha, I can integer divide and you can't!" You now know better. Hi there. I have a program that generates a random exam with digits 0 -9. I have managed to generate random symbols to appear inbetween each question and it now accepts an answer. What i need is that when a division sum is generated, i need another field beside the answer for the remainder. Here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Brittanica Template.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <style type="text/css"> <!-- .equals { color: #0F0; } --> </style> <!-- InstanceEndEditable --> <style type="text/css"> <!-- body { background-image: url(../Images/blackboard.jpg); } #Main_div { height: 700px; width: 680px; margin: auto; position: relative; top: auto; padding: 0px; } #header_div { height: 179px; width: 660px; position: relative; left: auto; top: auto; right: auto; bottom: auto; margin: auto; } #body_div { height: 550px; width: 660px; position: relative; margin: auto; } body,td,th { color: #FFF; } --> </style></head> <body> <div id="Main_div"> <div id="header_div"><img src="../Images/math.png" width="660" height="179" /></div> <!-- InstanceBeginEditable name="EditRegion3" --> <script language="javascript" type="application/javascript"> function runCode() { document.getElementById("txt_sum11").value = rndNumber(); document.getElementById("txt_sum12").value = rndNumber(); document.getElementById("txt_sum21").value = rndNumber(); document.getElementById("txt_sum22").value = rndNumber(); document.getElementById("txt_sum31").value = rndNumber(); document.getElementById("txt_sum32").value = rndNumber(); document.getElementById("txt_sum41").value = rndNumber(); document.getElementById("txt_sum42").value = rndNumber(); document.getElementById("txt_sum51").value = rndNumber(); document.getElementById("txt_sum52").value = rndNumber(); genOperators(); document.getElementById("hiddenField1").value = eval(document.getElementById("txt_sum11").value + document.getElementById("symbol1").value + document.getElementById("txt_sum12").value) document.getElementById("hiddenField2").value = eval(document.getElementById("txt_sum21").value + document.getElementById("symbol2").value + document.getElementById("txt_sum22").value) document.getElementById("hiddenField3").value = eval(document.getElementById("txt_sum31").value + document.getElementById("symbol3").value + document.getElementById("txt_sum32").value) document.getElementById("hiddenField4").value = eval(document.getElementById("txt_sum41").value + document.getElementById("symbol4").value + document.getElementById("txt_sum42").value) document.getElementById("hiddenField5").value = eval(document.getElementById("txt_sum51").value + document.getElementById("symbol5").value + document.getElementById("txt_sum52").value) } function rndNumber(){ var returnNumber; returnNumber = Math.floor(Math.random()*11); return returnNumber; } function validateCode(){ var val1 = document.getElementById("txt_answer1").value var val2 = document.getElementById("hiddenField1").value if (val1 == val2){ alert("First answer is correct") } var val1 = document.getElementById("txt_answer2").value var val2 = document.getElementById("hiddenField2").value if (val1 == val2){ alert("Second answer is correct") } var val1 = document.getElementById("txt_answer3").value var val2 = document.getElementById("hiddenField3").value if (val1 == val2){ alert("Third answer is correct") } var val1 = document.getElementById("txt_answer4").value var val2 = document.getElementById("hiddenField4").value if (val1 == val2){ alert("Fourth answer is correct") } var val1 = document.getElementById("txt_answer5").value var val2 = document.getElementById("hiddenField5").value if (val1 == val2){ alert("Fifth answer is correct") } } function genOperators(){ for (var i = 1 ; i <= 5 ; i++){ var operator = Math.floor(Math.random()*4)+1; var actualOp = ""; switch(operator){ case 1: actualOp = "+"; break; case 2: actualOp = "-"; break; case 3: actualOp = "/"; break; case 4: actualOp = "*"; break; } document.getElementById("symbol"+i).value = actualOp; } } </script> <style type="text/css"> <!-- body { background-color: #999; } body,td,th { font-weight: bold; color: #900; } --> </style> <form id="form1"> <center> <input type="button" name="btn_getNumber" value="Click here to begin" onclick="runCode()"/> </center><br/> <center> <input type="text" name ="txt_sum11" id="txt_sum11" /> <input name="symbol1" type="text" id="symbol1" size="1" maxlength="1" /> <input type="text" name ="txt_sum12" id="txt_sum12" /> <span class="equals">=</span> <input type="text" name ="txt_answer1" id="txt_answer1" /> <input type="hidden" name="txt_actualAnswer1" id="hiddenField1" /> </center><br/> <center> <input type="text" name ="txt_sum21" id="txt_sum21" /> <input name="symbol2" type="text" id="symbol2" size="1" maxlength="1" /> <input type="text" name ="txt_sum22" id="txt_sum22" /> <span class="equals">=</span> <input type="text" name ="txt_answer2" id="txt_answer2" /> <input type="hidden" name="txt_actualAnswer2" id="hiddenField2" /> </center><br/> <center><input type="text" name ="txt_sum31" id="txt_sum31" /> <input name="symbol3" type="text" id="symbol3" size="1" maxlength="1" /> <input type="text" name ="txt_sum32" id="txt_sum32" /> <span class="equals">=</span> <input type="text" name ="txt_answer3" id="txt_answer3" /> <input type="hidden" name="txt_actualAnswer3" id="hiddenField3" /> </center><br/> <center><input type="text" name ="txt_sum41" id="txt_sum41" /> <input name="symbol4" type="text" id="symbol4" size="1" maxlength="1" /> <input type="text" name ="txt_sum42" id="txt_sum42" /> <span class="equals">=</span> <input type="text" name ="txt_answer4" id="txt_answer4" /> <input type="hidden" name="txt_actualAnswer4" id="hiddenField4" /> </center><br/> <center><input type="text" name ="txt_sum51" id="txt_sum51" /> <input name="symbol5" type="text" id="symbol5" size="1" maxlength="1" /> <input type="text" name ="txt_sum52" id="txt_sum52" /> <span class="equals">=</span> <input type="text" name ="txt_answer5" id="txt_answer5" /> <input type="hidden" name="txt_actualAnswer5" id="hiddenField5" /> </center><br/> <center> <p> <input type="button" name="btn_submit" value="Submit Answers" onclick="validateCode()"/> </p> </center> </form> <!-- InstanceEndEditable --></div> </body> <!-- InstanceEnd --></html> I also need to know how i would display all of the results of the test. For example "You got - 5 out of 5" "Time Taken - 3 minutes" "Date - 24-06-2011" Thank you. Hello! I have an array of strings, like this: var strings= [ "car", "black", "word", "small", "paper", "doom", "elemental", "sword", "mouse" ]; Now i got a function newgame() and i wanna display random word from this array in rectangles gray styled... Here is the problem. I can make to display random words, but i dont know how i make this words with the css style together - rectangels around a char. But the words are different length so i dunno? When i press newgame button, i want for example to random a word from the array: for example word "paper" then i want it to be displayed like this [p] [a] [p] [e] [r], where [ ] are rectangels around the chars ( with the css style, like this: border: 1px solid #000; width:10px; background-color:gray; text-align:justify; padding: 5px 10px; i make a gray rectangle border around the char, but how can i make it work with random words? How can i make it work? Any help please! I'm trying to find a much simpler way than this current script I am using to generate and print a random word. I don't want to have to name each word but instead just include a very large list of about 300,000 words that javascript uses to pull a random word out of. Can you please help me out?? The list of words I have is a straight list with no commas or anything. I am currently outputting to a text box, but I am looking to generate words according to users input. For example, a user wants 500 words starting with the letter "b" and is less than 5 characters long appended to the character "de." Any help would be awesome! Even a right direction. I'm also willing to pay some for such a script if need be. Thanks! Here's my code: Code: <SCRIPT LANGUAGE="JavaScript"> <!-- var NumberOfWords = 28 var words = new BuildArray(NumberOfWords) words[1] = "czarevitch" words[2] = "brightwork" words[3] = "verkrampte" words[4] = "protectrix" words[5] = "nudibranch" words[6] = "grandchild" words[7] = "newfangled" words[8] = "flugelhorn" words[9] = "mythologer" words[10] = "pluperfect" words[11] = "jellygraph" words[12] = "quickthorn" words[13] = "rottweiler" words[14] = "technician" words[15] = "cowpuncher" words[16] = "middlebrow" words[17] = "jackhammer" words[18] = "triphthong" words[19] = "wunderkind" words[20] = "dazzlement" words[21] = "jabberwock" words[22] = "witchcraft" words[23] = "pawnbroker" words[24] = "thumbprint" words[25] = "motorcycle" words[26] = "cryptogram" words[27] = "torchlight" words[28] = "bankruptcy" function BuildArray(size){ this.length = size for (var i = 1; i <= size; i++){ this[i] = null} return this } function PickRandomWord(frm) { var rnd = Math.ceil(Math.random() * NumberOfWords) // Display the word inside the text box frm.WordBox.value = words[rnd] } //--> </SCRIPT> Is there any way to convert a number stored as a javascript variable into words? Something like... Code: var num=120394; then run that var through a function and have the output be: One hundred twenty thousand three hundred ninety four Any help would be great! Hi guys, Do you know a function for banning certain words being inputted by the user eg I want to stop a user uploading offensive words and code tags like <script>, <div> etc.. and messing with the site display Thanks I want to create a web form that can substitute words in a URL with the inputted values. I realize the form is easy in HTML, and that's about all I'm good for. But I think the substitution must be done by javascript. For example: example.com/whatever/XXX/YYY I want the form to be able to replace the "XXX" and "YYY" with inputted values of the form, then I want it to direct to that URL when I click the "submit" button. Or just output the new URL as a link, whichever is easier. I know this has to be very basic javascript that is easy to do but I know next to nothing about this kind of thing. Sorry for the noob question but hours of googling/trying to figure out basic javascript has left me at a loss still. Help greatly appreciated! I am trying to understand what this javascript function is trying to accomplish. Can anyone breifly describe what the function is doing? If you can do a break down that would be great for me to understand this a bit better. I apreciate any assistance! Code: /* Engagement Score */ s.eVar5=s.engagementScore('event31','s.pageName|products|1>s.events|event6|1>s.eVar3|competitiveMatrix.pdf|1>s.pageName|webLeadsForm:complete|1>s.events|purchase|1>s.events|event4|1>s.events|scView|1'); /* Engagement Score Tracking */ s.engagementScore = new Function("e","l","c",""); var A,B,C,D,E,F,G,H,I,J; I=J=''; A=s.split(l,'>'); B=A.length; E=c?c:'s_ES'; //D=value of cookie with name 'E' D=s.c_r(E); if(!D){ for(C=0;C<B;C++){ D=D+'0,'; } } D=s.split(D,','); for(C=0;C<B;C++){ F=s.split(A[C],'|'); G=eval(F[0]); if(D[C]==1){ I=I+'1,'; } else if(G!=undefined){ if(G.indexOf(F[1])>-1&&D[C]!=1){ s.events=s.apl(s.events,e,',',2); s.products=s.apl(s.products,';;;;'+e+'='+F[2],',',2); I=I+'1,'; J='+'+F[2]; } else { I=I+'0,'; } } else{ I=I+'0,'; } } s.c_w(E,I,0); return J; s.split=new Function("l","d",""+"var i,x=0,a=new Array;while(l){i=l.indexOf(d);i=i>-1?i:l.length;a[x"+"++]=l.substring(0,i);l=l.substring(i+d.length);}return a"); Hello, I wanted to know how can I go through all the text on a page and store a unique ocurrence of every word in a array. Just point me on the right direction if you may. Got lost in translation... Lg Hello. I want to validate via javascript an input text box. What i want is to have at least two words ( not letters ). At this moment i did validation to detect if the input is empy: <script> function validateForm() { var x=document.forms["myForm"]["s"].value if (x==null || x=="") { alert("Nu ati introdus nimic."); return false; } } </script> But how to validate to have at leat two words inside my input area. Thank you. Here is my form: <form name="myForm" method="get" id="searchform" onsubmit="return validateForm()" action="<?php bloginfo('home'); ?>/"> <div><input type="text" value="" name="s" id="s" /> <input type="hidden" name="cat" value="19" /> <input type="submit" id="searchsubmit" value="Cauta document" /> </div> </form> Sorry, not sure if I need Javascript for this so I posted it in the html forum as well I'm looking to create a simple page where a user can copy and paste a list of ingredients and then push a button to search that list for a number of key words. Key words: Amodimethicone, Trimethylsilylamodimethicone, Glycerin, Trideceth-12, Behenoxy, Bisamino, Aminoethyl, PG-Propyl, Phenylpropyl, Methicone, Cyclomethicone, Cyclopentasiloxane, Cyclohexasiloxane, Cyclopentasiloxane, Dimethiconol, Trimethylsiloxysilicate, Silicate, Siloxy, Trimethylolpropane, Diisostearoyl, Copolyol, Dodecylbenzenesulphonate, Diphenyl, silicone, Methicone, Simethicone, Trisiloxane, sulfate, Myreth, Lauryl, Laureth, Sulfonate, dodecylbenzenesulfonate, Xylenesulfonate, Ammonium, Isethionate, Sulfoacetate, Sarcosinate, Sulfosuccinate, Carboxylate, Taurate, glycinate I don't care how they are alerted if any of the key words match their ingredients pop up, highlight, whatever. *Incase anyone is wondering it is to search hair products for any form of silcones or sulfates since many people wish to avoid them but they come in many different forms. Thanks!! Hello, I have a regular expression that returns multiple matches. For e.g. If the user types a string "980ee,34223,werw" in a textbox, the regular expression match returns "ee" and "werw". I would like to highlight both "ee" and "werw" in the textbox. How can I achieve this? Thank you. I have the 10000th word and I want to put the this symbols [ and this ] the beginning and end of words .. so my question is .. how do I put the symbol is simultaneously the 10000th word that is .. there is not any program that can do such ... please help .. example : [can] [you] [me] [and] [ask] [google] [yahoo] [and over 10000 ++ more] I have a Text Box which i wish to Place Words into it, once i click the Button it should Split the Words into Characters E.G I enter Before in Text box it should Should B E F O R E Code: <script language="javascript"> function getTag(){ var string = document.getElementById("tag"); var array = string.getElementById("tag"); var finishedArray = []; for (var i = 0, il = array.length; i < il; i++) { var temp = array[i].getElementById(","); for (var j, jl = temp.length; i < jl; j++) { finishedArray.push(temp[j]); destLayer = document.getElementById('splitResponse'); destLayer.innerHTML=''; } } } </script> <h3>Sentence Splitter</h3> <input name="tag" type="text" id="tag" size="30" autocomplete="off"/> <button onClick="getTag();" value="Click"/>Click</button> <div id="splitResponse"></div> <div class="section"></div> </div> Hi all, as the title says i am trying to keep count of the number of words a user has typed into a textbox. I have an emoticon box, something like the one that you see when you reply/start a thread here. The mouseup event fires off when the user clicks on an emoticon to display it in the textbox. The problem here is, my code below does not start counting if an emoticon is added when theres nothing in the textbox (making the emoticon the first item). I can continue to add more smileys in and they will be counted in the word limit, but the first one will not be included in the count, unless the user clicks somewhere on the screen. How can i fix this problem? Code: //#message is the textbox $(document).ready(function() { var characters = 100; $("#remainder").append(characters+"words left"); $("#emoticonsbox").mouseup(function() { var remaining = characters - $("#message").val().length; $("#remainder").html(remaining+"words left"); }); }); |