Permalink
Browse files

validation

  • Loading branch information...
1 parent 7e7aeb0 commit 96e4bb01d3ef8d95fab1b2e789c00e6c60220fa0 Andrew Pennebaker committed Apr 15, 2012
Showing with 27 additions and 11 deletions.
  1. +21 −5 public/ajax.js
  2. +3 −3 public/stylesheet.css
  3. +3 −3 server.js
View
@@ -38,17 +38,33 @@ function showPrice(name, edition, trader) {
o = $.parseJSON(response.responseText),
lowPrice = parseFloat(o.lowPrice);
+ message = "";
+
if (trader == "a") {
- cumulativePriceA += lowPrice;
+ if (isNaN(cumulativePriceA) || isNaN(lowPrice)) {
+ message = "?";
+ alert("No price information for Name: \"" + name + "\" Edition: \"" + edition + "\"");
+ cumulativePriceA = NaN;
+ }
+ else {
+ cumulativePriceA += lowPrice;
- var message = "Total: $" + cumulativePriceA.toFixed(2);
+ message = "Total: $" + cumulativePriceA.toFixed(2);
+ }
totalA.html(message);
}
else {
- cumulativePriceB += lowPrice;
+ if (isNaN(cumulativePriceB) || isNaN(lowPrice)) {
+ message = "?";
+ alert("No price information for Name: \"" + name + "\" Edition: \"" + edition + "\"");
+ cumulativePriceB = NaN;
+ }
+ else {
+ cumulativePriceB += lowPrice;
- var message = "Total: $" + cumulativePriceB.toFixed(2);
+ message = "Total: $" + cumulativePriceB.toFixed(2);
+ }
totalB.html(message);
}
@@ -209,4 +225,4 @@ function trace(message, line, input) {
function traceFormat(line, input) {
trace("Syntax error", line, input);
-}
+}
View
@@ -17,15 +17,15 @@ nav h1, button {
}
button {
- width: 100%;
+ width: 80%;
margin-top: 1em;
padding: 0.5em 0 0.5em 0;
font-size: 150%;
}
a, a:visited { color: black; }
-#totalA, #totalB { padding: 1em; }
+#totalA, #totalB { padding: 5em; }
#fail { color: red; }
#warn { color: orange; }
@@ -39,4 +39,4 @@ nav {
nav p {
font-size: 80%;
-}
+}
View
@@ -56,9 +56,9 @@ function server() {
res.writeHead(200, {"Content-Type": mimetypes[format]});
formatters[format](query, res);
});
- }).listen(80);
+ }).listen(8633);
- console.log("Server started at http://localhost/");
+ console.log("Server started at http://localhost:8633/");
}
-server();
+server();

0 comments on commit 96e4bb0

Please sign in to comment.