Recursion Programming
Aug 1, 2007I am trying to program a script that will output the solution for the towers of hanoi problem, the only problem is that it will not output the solution it just hangs while calculating. Code:
View 2 RepliesI am trying to program a script that will output the solution for the towers of hanoi problem, the only problem is that it will not output the solution it just hangs while calculating. Code:
View 2 Replieswanna know how we can get the animation effect using the recursion method. following is the code:
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideToggle(2000); // i wanna call this jquery animation recursively
[code]....
I am trying to create a family tree, parents / grandparents etc, of a single person... My database etc is already working but I cannot find any working examples that I can make sense of... Each of my records has a name, dob and id of each parent.... How can I get X generations from this.. I thought something like this might work.. GetParents For each parent GetParents And so on... But I have no idea how to put this into code...
View 2 Replies View RelatedI am having a problem finding the syntax for recursively adding images to a webpage using javascript. I have some pseudo code but no js.
already in a folder function 1 for each file in folder add file to webpage next folder function2 function2 for each folder within folder call function 1
I know the code isn't all that clear, but that's the best way I can describe it.
I am having trouble with a recursive function I created to list out the indexes and values of various nested objects.
var macros={
CTRL: {
ALT: {
ENTER: "<br />",
P: "<p>.</p>",
A: "<a href="">.</a>",
_1: "<h1>.</h1>",
_2: "<h2>.</h2>",
_3: "<h3>.</h3>",
_4: "<h4>.</h4>",
_5: "<h5>.</h5>",
_6: "<h6>.</h6>"
}}};
I want to print out the whole 'bread crumb trail' to each object, ie CTRL ALT 6: <h6>.</h6>, but at the moment my function prints out CTRL ALT twice for 'ENTER' and then never again. The function:
function printObj(obj) {
for(i in obj) {
var n=i.replace("_", "");
document.write(n);
if(typeof obj[i]=="string") {
document.write(":");
document.write(" "+obj[i].replace(/</g, "<").replace(/>/g, ">"));
} else {
document.write(n);
}
if(typeof obj[i]=="object") printObj(obj[i]);
document.write("
");
}}
printObj(macros);
The current output:
CTRLCTRLALTALTENTER: <br /> P: <p>.</p> A: <a href="">.</a> 1: <h1>.</h1> 2: <h2>.</h2> 3: <h3>.</h3> 4: <h4>.</h4> 5: <h5>.</h5> 6: <h6>.</h6>
I am using the module pattern and private/public methods. I'm having a problem where the private method is using setTimeout() to call itself recursively, but I can't get the syntax right. Code:
View 1 Replies View RelatedI have this script. It's supposed to give the Fibonacci numbers but the recursion won't work. It just prints out 1 number that the user entered and that's it. In IE6 it prints 1 number but in Firefox it prints the same number an infinite number of times. Whats going on? Here is the script:
<html>
<head>
<script language = "javascript">
function fib(form)
{
var fibVar = Number(document.myform.inputbox.value);
document.write(fibVar);
if(fibVar == 0 || fibVar == 1)
return fibVar;
else return fib(fibVar - 1) + fib(fibVar - 2);
}
</script>
</head>
<body>
<form name="myform" action="" method="get">
<input type="text" name="inputbox"><br>
<input type="button" name="button1" value="Calculate"
</form>
</body>
</html>
In some pages of my website I use a code like the following:
for (var n = 0; n < getTagsArray("SPAN").length; n++){
//SPAN is just an example. I also use other tags
tag = getTagsArray("SPAN")[n];
//make something with tag...
}
function getTagsArray(Tag){
if(document.all){ //Internet Explorer
return document.all.tags(Tag);
}
else if (document.layers){ //Netscape
eval("return document.tags." + Tag);
}}
I want to put all browser-specific code inside the getTagsArray
function. So far, I've programmed only for Internet Explorer (my
browser), but now I want to make my website visible to all browsers.
I'm not sure about the getTagsArray function. Is it right or is there
a better way to do the same thing? And how can I extend that function
to make it work in other browsers?
Finally, where can I find some information about cross-browser
programming? I have the javascript reference for Internet Explorer and
Netscape, but I know nothing about other browsers.
Have someone experience with javascript programming on windows mobile. the event.keycode will not work.
View 3 Replies View RelatedI have to develop a program for translating a word in english into pig latin, I have most of it done, it runs but I can't make it define if the first letter see if it's a consonant or not, if it's a consonant take the consonant out and put"ay" at the end and if it's not consonant just put the "ay" at the end of the word, and it has to give an error message if user puts in more than one word, it's done in 2 classes, been stuck on this for hours now have done a lot of research but seems like everyone is doing a more advanced program. Here's my program:
First class
public class piglataintran
{
private String translate;
[code]....
What type of Editor do you use for your JavaScript programming?
View 5 Replies View RelatedFirebug returns an error and I like to ask you how I could improve my code.
[Code]...
I would like to know if there is a simple way to show all elements of that variable?
var collectionElements = {
teste: {
var1: 'teste[]',
[Code].....
With this function my firebug Console outputs only the last object(3th node) with its child object.
I just released javascript lib that really helps to develop robust and clear js-scenarios following the OOP directions. The library is compatible with wide range of browsers on different platforms, including Netscape 4.x, Netscape 6.x, Netscape 7.x, Opera 6, Opera 7, Mozilla 1.0, IE 4, IE 5, IE 6.
View 3 Replies View RelatedCan someone tell me all the OOP's that can be made from javascript.
View 3 Replies View RelatedWhen I click the compute button, it does not do anything. It does not go to function CALCULATE and do its stuff.
[Code]...
I must admit that the more I use and learn JavaScript, the more
convinced I am that it is one of the most expressive languages I know.
Without ways to access file i/o or databases though, can JavaScript be
considered as a serious general purpose language?
How do you position an alert or prompt to anywhere on the screen. How do you change the font for the alert or prompt (i.e Hebrew)
View 3 Replies View RelatedThe documentation on e.g. the fadeIn() method does not specify any constraints on the callback argument. Does that mean that 'anything will work'? Specifically, is recursion allowed?I want to know whether jQuery design has deliberately taken this into account. Yes, I can read the source code. No I don't plan to do so (for now), since I consider it an essential gap in the documentation.[code]
View 5 Replies View RelatedI am trying to make a round corners script in object oriented programming method. This is purely for learning purposes.
The script is no where near complete but I am already having problems with it.
I am trying out the techniques described in 'David Flanagan ' text book 'JavaScript: The Definitive Guide, 5th Edition'
This code is called from html page which once working will place a round container around element
The selector parameter in Custom_rounded_container function is defined because only the else part of the if statement in Custom_rounded_container is executing. I put this in because few people at other forums thought the problem was because of the selector parameter being undefined.
External Javascript file
I am trying to make a round corners script in object oriented programming method. This is purely for learning purposes.
The script is no where near complete but I am already having problems with it.
I am trying out the techniques described in 'David Flanagan ' text book 'JavaScript: The Definitive Guide, 5th Edition'
This code is called from html page which once working will place a round container around element
Code:
Javascript functions below
Code:
Trying to figure out OO programming for JavaScript and I'm totally lost.
Here's what I'm trying to do:
I'm posting search data to a PHP form to run a query on a database.
The structure is sort of like this:
So I'm thinking I need to create search objects or arrays. Initially, I thought I could do something like this:
Code:
This doesn't seem to work. It says object not defined whenever I try to do something.
I've also tried creating a JSON object like this:
Code:
This will allow me retrieve the data like I want to:
Code:
The problem is I can't figure out how to add data to the JSON object without manually typing it in. I need to be able to loop through form elements on my HTML page and set them to these variables. I'm using jQuery and doing something like this:
Code:
I am using jQuery form plugin to submit my form. It has a file element and when where I am submitting it I am getting "too much recursion" in Firefox. It looks fine in IE 8. It works fine if I submit the form without selecting any file.
I am calling ajaxForm() methid this way.
jQuery("#myForm").ajaxForm();
I am making a php/mysql epos system for my shop which will be run from a browser on my shop PC. I have large buttons which I would like to be able to 'click' by pressing something like the F-buttons at the top of the keyboard. Is it possible to override the standard button shortcuts for a web page. This is only going to be on my shop computer so accessibility is not a problem.
View 2 Replies View Relatedthis code:
$(document).ready(function() {
$('body').click(function(evt) {
if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) {
$('a[href=#2]').trigger('click'); } });});
gives me and error of "too much recursion"
some "if" statements. I am writing a script to write to the document in hexidecimal numbers. I am probably going about it the long way. Keep in mind that this is only an excercise for me to practice recursion with conditional statements.
Here is what I got going on:
I see on my page: #00, #01, ... to #0f, Now, I would like to say:
Or something like:
At which point I would like to say:
The whole picture at the end would be #00, #01, all the way to #ff and back down to #00 again. WScript.Quit (Just kidding about WScript.Quit Lol!) That is unless javascript has access to Windows Script Host.
Anyway, After counting up to #ff, count back down to #00. Write all that to the document for proof and the script is done.