## The Arc Challenge: PHP and JavaScript

Take the Arc Challenge. For the lazy, here is the problem:

Write a program that causes the url said (e.g. http://localhost:port/said) to produce a page with an input field and a submit button. When the submit button is pressed, that should produce a second page with a single link saying "click here." When that is clicked it should lead to a third page that says "you said: ..." where ... is whatever the user typed in the original input field. The third page must only show what the user actually typed. I.e. the value entered in the input field must not be passed in the url, or it would be possible to change the behavior of the final page by editing the url.

I ignored the part about what the URL has to be, because that would just be annoying. The point of Arc is to write things in the most efficient way possible, and the whole language is built around helping you do that. The point of this problem is to illustrate that Arc does this very well.

In Arc, a solution looks like this:

(defop said req
(input "foo")
(submit)))

In PHP:

session_start();

if (isset($_SESSION['said'])) { echo 'You said: ' . htmlentities($_SESSION['said']); //prevent XSS lol
unset($_SESSION['said']); } else if (isset($_POST['said'])) {
$_SESSION['said'] =$_POST['said'];
} else {
echo '<form method="post" action=""><input type="text" name="said"/><input type="submit"/></form>';
}

And in JavaScript:

function getCookie(name) {
for (var i = 0, len = cookies.length, cookieParts; i < len; i++) {
}
}

return null;
}

if (said === null) {
var input = document.createElement("input");
input.type = "text";
var button = document.createElement("button");
button.appendChild(document.createTextNode("Submit"));
button.onclick = function() {
window.location.href = window.location.href;
}

document.body.appendChild(input);
document.body.appendChild(button);
} else if (page === 2) {
}