LinuxQuestions.org
Help answer threads with 0 replies.
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:38 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, 04:25 PM   #2
ShadowCat8
Member
 
Registered: Nov 2004
Location: San Bernardino, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 261

Rep: Reputation: 52
Well,

I took a few minutes to check what your code was doing in the scratchpad and I got it to return the following:
Code:
==> "scissors"
>
and that was it.
Looking at the code, I see you are assigning the function to var compare but you never seem to do anything with compare.
Code:
var compare = function(choice1, choice2) {   
	if (choice1 === choice2)   {
...<snip>...
			}     else {
				return("rock wins");     
				
			}   
			
		} 
		
	};
Perhaps set up an alert to take the return of the function and put it out to the user?

HTH. Let us know.
 
  


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
LXer: Java in the web browser in Debian Squeeze -- you have to add it LXer Syndicated Linux News 0 12-03-2010 06:20 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 06:10 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