-2

Hi I want to shorten this: document.write("").

Instead i made my function:

function myFunc() {
    document.write()
}

and I want that ill be able to modify it like this: myFunc("hello world") but it did not work.

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105

1 Answers1

1

Your function needs to take an argument. Right now, you're trying to pass it one, but it doesn't take any, then you call document.write() with no arguments, so it doesn't write anything. You can add a parameter like this:

function myFunc(s)
{
    document.write(s);
}
KSFT
  • 1,774
  • 11
  • 17
  • ok, so lets say I want a function and when ever I call it I want to specify the string (what i want it to say on the web) with the parameters.. – mendel goldstein Apr 01 '15 at 18:42
  • like this: myFunc(hello world) - it should show on page "hello world" – mendel goldstein Apr 01 '15 at 18:43
  • @mendel goldstein Guess you could try `myFunc("hello world");` ... but to you question 'how do I do it?' ... Do what? What exactly are you trying to accomplish? – yas Apr 01 '15 at 18:59
  • @dave I'm trying to create an output for my js on the webpage instead of using the alert function – mendel goldstein Apr 01 '15 at 19:06
  • If this is for debugging, you may want to look at: http://stackoverflow.com/questions/4539253/what-is-console-log. If not for debugging purpose, you can use DOM methods to insert or update element content dynamically, see http://stackoverflow.com/questions/11907053/how-do-i-add-something-to-my-html-using-javascript-without-erasing-the-whole-pag – yas Apr 01 '15 at 19:08