#1
|
|||
|
|||
I am a programmer without a compiler, and a sh-tty one at that.
I like programming. I've used VB, java, perl, QBASIC (woot!), and that's about it.
However, my linux box is down, and I like the flexibility of programming using javascript, considering that windows seems to run it just fine with minimal effort on my part. ---------- So I'd like to know a few things about javascript programming. 1) Can they output to text files. * 2) Can they output to HTML files. * 3) How do I make arrays? 4) How do I gather user input and make a WHILE loop? * easily, hopefully. ---------------------------------------------- link The following shows some code with the alert and prompt statements, which is part of what I need. It also shows a function (though no function variables are used), and a for loop. It shows arrays being used. So basically, I need to know the while loop and how to export to text. This shows a while loop --- Alright... so basically everything's been answered except the "how to output to text and html" thing... If I could get that, I'd be pretty happy. [img]/images/graemlins/smile.gif[/img] --- Edit: function with an argument |
#2
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
The javascript can produce text output as in:
document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt |
#3
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
Out of curiosity, what did you find difficult about using Perl on Windows?
It would seem that for what you're looking for (quick text processing) Perl would be the thing. |
#4
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
The javascript can produce text output as in: document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt [/ QUOTE ] document.write(string) seems cool... ooc, how do I specify what text file it's printing to? Would I have to use weird java-esque file names: c://foldertowriteto/file.txt or would a standard DOS filepath be okay? I'd prefer to execute the file by double-clicking on it on my desktop or somesuch, so . [img]/images/graemlins/smile.gif[/img] FWIW, the stuff that I've found on the java document object model is very complex stuff. It's way more powerful than what I need to use it for (though it does appear to do what I need to use it for)... Any idea where I could find a dummy's guide to this? --Dave. |
#5
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
Out of curiosity, what did you find difficult about using Perl on Windows? It would seem that for what you're looking for (quick text processing) Perl would be the thing. [/ QUOTE ] This would be for iterative bet-size calculations. Java should do okay for this purpose. But yes, perl totally pwns for... well... everything actually. [img]/images/graemlins/cool.gif[/img] I tried setting up perl on windows once and it was a huge hassle. On linux it was very easy (might have even been part of the core that I used). |
#6
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
Ok first of all we need to set things straight. Javascript is not an actual programming language, that's just scripting. Furthermore Javascript doesn't get compiled, and you'll not get Javascript to write files on your PC; it's simply just not made for taht purpose.
Why not use Java if you've used that before? Using Java you can make console apps if you want, and then you can get user input by making an infinite while loop. Just download Java 1.5 from Sun's site, then just find your javac location, and you're set with a compiler and everything. |
#7
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
You may want to check out ActivePerl, a pretty good (from what I've heard, I don't do Perl) package with a Windows port. You might also want to consider Cygwin, which can be nice if you're familiar with Unix/Linux.
|
#8
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
[ QUOTE ] The javascript can produce text output as in: document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt [/ QUOTE ] document.write(string) seems cool... ooc, how do I specify what text file it's printing to? Would I have to use weird java-esque file names: <a href="c://foldertowriteto/file.txt" target="_blank">c://foldertowriteto/file.txt</a> or would a standard DOS filepath be okay? I'd prefer to execute the file by double-clicking on it on my desktop or somesuch, so . [img]/images/graemlins/smile.gif[/img] FWIW, the stuff that I've found on the java document object model is very complex stuff. It's way more powerful than what I need to use it for (though it does appear to do what I need to use it for)... Any idea where I could find a dummy's guide to this? --Dave. [/ QUOTE ] The security around web browsers will prevent Javascript from writing directly to the hard drive. This is intended to prevent malicious code from affecting computers. The best way to deal with a text file save is to write it to an html text field and then copy and paste the text into a new text file. As for good JS resources, try javascript.internet.com. There are hundreds of scripts here that might point you in the right direction. |
#9
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
It can't write to a file. It can output to your browser which you can then save to a file. Or if you are somehow running it from the command line then you can "pipe" the output to a file using your operating system functions to redirect output to a file. But the language itself does not support any Input/Output commands.
I'm with the others, you will run into your boundaries soon with JavaScript. Perl or PHP isn't that huge of a leap to screw around with, but your upside capabilities to progress into more involved applications are significant. |
#10
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
I tried setting up perl on windows once and it was a huge hassle. On linux it was very easy (might have even been part of the core that I used). [/ QUOTE ] I will second Perl from ActiveState. It's prebuilt and comes with a nice installer which will also make the .pl file association for you. While I could compile my own Perl on Windows, it's so much easier to use the ActiveState build. There is also a pretty comprehensive module repository, so you don't have to use CPAN directly (though you still can, if you wish). For information on that, look at Perl Package Manager aka "ppm" when you get the ActiveState installation done. If you don't have a compiler, that's the best way to install packages that aren't pure perl. Regards, T |
|
|