Post HTML5, Javascript & CSS3 queries here

OP
vickybat

vickybat

I am the night...I am...
^^ I don't think geolocation can do that. It just returns latitude and longitude of current position.
 

hari1

In the zone
Why does this code not work properly?
I am learining javascript on codecademy and just learn about functions. I built the rock, paper and scissors game and tried to include the features given in the suggestion in the final lesson. But it does not work. When I enter the input of rock, paper or scissors, nothing happens. How to fix it? Is the 'return' preventing the game to run properly in the compare function?




var game = function () {
var userChoice = function (user) {
user = prompt("Do you choose rock, paper or scissors?");
if ((user != "rock") && (user != "paper") && (user != "scissors")) {
alert("The input is wrong.");
userChoice();
} else {
return user;
}
};
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!";
}
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 === "rock") {
return "rock wins";
} else {
return "scissors wins";
}
}
};
compare(userChoice(), computerChoice);
};
game();


This is the first time I am learning coding after learning HTML and CSS and I need some help.
 

furious_gamer

Excessive happiness
Please use jsfiddle to post your codes. This way it is easy for a guy to debug and so you will see the changes also.
 

furious_gamer

Excessive happiness
Are you sure you are printing something? You are just simply returning value, so your code just works fine. Put alert o you know that it is working.

For all JS coders, use console.log() or alert() to debug.

Code : Edit this Fiddle - jsFiddle
 

hari1

In the zone
Are you sure you are printing something? You are just simply returning value, so your code just works fine. Put alert o you know that it is working.

For all JS coders, use console.log() or alert() to debug.

Code : Edit this Fiddle - jsFiddle

Thanks! It worked:razz: See this fixed code.
Edit this Fiddle - jsFiddle
Also, how do I stop the dialogs if the user presses cancel button when selecting rock, paper and scissors?
 

furious_gamer

Excessive happiness
The problem is you are code is linear. Just make it little blocks(means, write functions separately instead of writing nested functions), so while user clicking Cancel, nothing will happen.
 
Last edited:

hari1

In the zone
Thanks, for your advice. I am beginning to learn coding right now. I will try new ways to do the same thing to understand it better.
 

furious_gamer

Excessive happiness
When you write functions in js, write them in separate blocks. This way you can take full control of it's behavior.

Like :
Code:
function game() {...}
function compare(){...}
function getInput(){...}

Call them in whatever order you want.
 

De Cay

a Dweeb!!
I'm working on a project where accessing the inbuilt webcam is required!!
Can anybody provide me source code for accessing it??
 

furious_gamer

Excessive happiness
I assume you want it in jquery. Because you didn't mention which language are you coding.

jQuery webcam plugin &bull; Code is poetry
 

gigyaster

Journeyman
Hello,
an anyone tell me which font is used in Google's Homepage (Google.com) in the header part ?? I need to know this as I'm trying to design a similar looking header.

By header I mean the black bar at the top that has '+You, Gmail etc etc'

I tried 'Inspect Element' in my browser but that did not help me.

Kindly help.
 

gigyaster

Journeyman
Re: Post HTML5, Javascript &amp; CSS3 queries here

^^ Thanks a lot :)
BTW, how did you figure that out ?

Got another trouble ??

how do I create the buttons that are used in Google's Homepage ?? They are way too different form the standard buttons.

PS: I'm done with all my issues, I created the button and things became simple with CSS3. Thanks anyway.
 
Last edited:
Top Bottom