LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2013, 11:47 AM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
Java script does not work from a web browser


Code:
var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if (computerChoice < 0.34) {   computerChoice = "rock"; } else if (computerChoice <= 0.67) {   computerChoice = "paper"; } else {   computerChoice = "scissors"; } var compare = function(choice1, choice2) {   if (choice1 === choice2)   {     return("The result is a tie!");   }   else   {     if (choice1 === "rock") {       if (choice2 === "scissors")       {         return("rock wins");       }       else {         return("paper wins");       }     }   }   if (choice1 === "paper")   {     if (choice2 === "rock")     {       return("paper wins");     }     else {       return("scissors wins");     }   }   if (choice1 === "scissors")   {     if (choice2 === "paper")     {       return("scissors wins");     }     else {       return("rock wins");     }   } };

This code works when running through a javascript engine, but it's not working from a webserver. What must I do, so that it will work correctly in a web browser if i added the code to my vps?

http://www.codecademy.com/courses/ja...s/3/scratchpad
 
Old 04-01-2013, 12:37 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
What do you mean it doesn't work from a web browser? I pasted that into Chrome's Javascript console and it worked just fine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java script does not work from a web browser fakie_flip Programming 1 04-01-2013 04:25 PM
Need help with Web Browser - Java and more KirkShanahan Debian 3 12-30-2008 11:23 AM
vnc server with java for connecting with web browser fakie_flip Linux - Software 5 04-05-2006 09:18 PM
Java and Web Browser problems. RHLinuxGUY Linux - Software 1 09-25-2005 11:01 AM
please tell how to make a plugin for a web-browser (konqueror) using c++ / Qt / Java gajaykrishnan Programming 1 07-22-2004 11:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration