Want more features on Pastebin? Sign Up, it's FREE!
Guest

Example JavaScript

By: a guest on Nov 26th, 2013  |  syntax: JavaScript  |  size: 1.92 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function reverseString(string) {
  2.     var i = string.length;
  3.     var output = [];
  4.  
  5.     while (i--) {
  6.         output.push(string.substring(i, i + 1));
  7.     }
  8.  
  9.     return output.join("");
  10. }
  11.  
  12. function stringToASCII(string) {
  13.     var chars;
  14.     var i;
  15.     var output = [];
  16.  
  17.     switch (typeof string) {
  18.     case "string":
  19.         chars = string.split("");
  20.         i = chars.length;
  21.        
  22.         while (i--) {
  23.             output.push(chars[i].charCodeAt());
  24.         }
  25.  
  26.         output.reverse();
  27.         break;
  28.     default:
  29.         return -1;
  30.     }
  31.  
  32.     return output.join(", ");
  33. }
  34.  
  35. function menuStub() {
  36.     var input = parseInt(prompt("Enter a digit from 1 to 4:"), 10);
  37.     var message = "You've called Menu Option: ";
  38.    
  39.     switch (input) {
  40.     case 1:
  41.         alert(message + input);
  42.         break;
  43.     case 2:
  44.         alert(message + input);
  45.         break;
  46.     case 3:
  47.         alert(message + input);
  48.         break;
  49.     case 4:
  50.         alert(message + input);
  51.         break;
  52.     default:
  53.         alert("You have not entered a digit from 1 to 4.");
  54.     }
  55. }
  56.  
  57. function emailProgram() {
  58.     var email = {
  59.         address: "",
  60.         subject: "",
  61.         messageBody: "",
  62.    
  63.         Send: function () {
  64.             var output;
  65.  
  66.             output = "Address: " + this.address + "\r\n" +
  67.                      "Subject: " + this.subject + "\r\n" +
  68.                      "Message: " + this.messageBody + "\r\n";
  69.  
  70.             alert(output);
  71.             alert("Your message has been sent.");
  72.         }
  73.     };
  74.  
  75.     do {
  76.         email.address = prompt("Enter E-mail Address of recepient: ",
  77.                 email.address);
  78.         email.subject = prompt("Enter E-Mail subject:", email.subject);
  79.         email.messageBody = prompt("Enter Message:", email.messageBody);
  80.     } while (email.address === "" || email.subject === "" ||
  81.              email.messageBody === "");
  82.  
  83.     email.Send();
  84. }
clone this paste RAW Paste Data