0

I am new to javascript, but is this valid?

<script type="text/javascript"> 
    if (condition()) { 
        location = "http://example.com/foo/bar/baz"; 
    } 

function condition()
{
if(something)
return true
else
return false
</script> 

I am trying to write a javascript that goes insdie of content editer web part inside of SharePoint. Thanks.

2
  • 1
    You tried it and decided it was (or wasn't) valid because ____? Commented Nov 11, 2010 at 22:21
  • I don't think SO should be used as spell check for your JavaScript. There is no question here! Commented Nov 11, 2010 at 22:23

4 Answers 4

3

It's almost valid (needs a closing }), you can call a function in or as an if() condition.

It should have the } on the end:

function condition() {
  if(something)
    return true;
  else
    return false;
}

Or much simpler:

function condition() {
  return something;
}

You can test it here.

Sign up to request clarification or add additional context in comments.

Comments

1

No, your missing a } at the end of your condition function.

Comments

0

No, but this is:

<script type="text/javascript"> 
    if (condition()) { 
        location = "http://example.com/foo/bar/baz"; 
    } 

function condition()
{
  if(something)
    return true;
  else
    return false;
}
</script> 

Comments

0

No, You need a closing curly bracket on your function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.