Week 2 - 121v6a.htm

<SCRIPT>

var theURL = prompt("Please enter an HTTP Site", "http://espn.go.com");

document.write(theURL.link(theURL.indexOf("http://") ? "http://" + theURL : theURL));

</SCRIPT>

The example illustrates how you can combine many steps into one.

(theURL.indexOf("http://") ? "http://" + theURL : theURL

if there isn't an http:// then (?) prefix http:// to theURL else (:) theURL => http://espn.go.com

now we have theURL.link(http://espn.go.com) or "http://espn.go.com".link(http://espn.go.com)

NOTE: Even though you can do something like this, you shouldn't because it is too difficult to read, understand, and most importantly way too difficult to maintain code like this.