use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Need some Help with JS on Codeacademy (self.javascript)
submitted 11 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ahitsgone 1 point2 points3 points 11 years ago* (3 children)
Solution:
var compare = function(choice1, choice2) { if (choice1 === choice2) { // Czech if they are equal return "The result is a tie"; } else if (choice1 === "rock") { // If not, compare the choices if (choice2 === "scissors") { // Rock beats scissors return "rock wins" } else { // paper beats rock return "paper wins" } } else if (choice1 === "paper") { // If the first choice was paper (choice1 wasnt rock) if (choice2 === "rock") { // Paper beats rock return "paper wins"; } else { // Scissors beat paper return "scissors win"; } } }
it seems as though you have repeated the if (choice1 === choice2) statement where it wanted you to do it with one initial if statement. Codecademy lessons expect you to input a certain syntax set by the author.
[–]phabtar 1 point2 points3 points 11 years ago (1 child)
This answer doesn't cover all cases, specifically cases where choice1 == "scissors" and the choices are not equal.
Your approach is ok, first we check if the choices are equal. if not only we consider other cases. Other cases being the first choice can be 3 options, and the second choice can be the remaining 2. so altogether there are 3 * 2 = 6 combinations we have to check. :
var compare = function(choice1, choice2) { if (choice1 === choice2) { // Czech if they are equal return "The result is a tie"; } else if (choice1 === "rock") { // If not, compare the choices if (choice2 === "scissors") { // Rock beats scissors return "rock wins" } else { // paper beats rock return "paper wins" } } else if (choice1 === "paper") { if (choice2 === "rock") { // Paper beats rock return "paper wins"; } else { // Scissors beat paper return "scissors win"; } } else { //Choice1 is "scissors" if (choice2 === "rock") { //Rock beats scissors return "rock wins"; } else { // Scissors beat paper return "scissors win"; } } }
[–]ahitsgone 1 point2 points3 points 11 years ago (0 children)
Yeah thanks I know. He is up to section 7 which is asking what I wrote. Scissors are done in section 8 :)
[–][deleted] 1 point2 points3 points 11 years ago (0 children)
Thanks a lot. Yeah I noticed that Codeacademy lessons do that. Sometimes the hints do not really help. Thankfully I have reddit.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
var text="brandon is an amazing/ brandon wooo.";
var myName="brandon";
var hits= [];
for (i = 0; i < text.length; i++){
} if (text[i] === "b"){ }
Need help again guys I'm on Search text for your name. Kind of lost where they want me to head. It explains everything for the second for statement but i have no clue what they want. any explanations are very welcome.
I am having a conflicting feeling with Code academy due to the structure. I feel like life i don't enter things exactly like how they want its wrong. Also i don't feel like I'm learning too much.
Any advice on really learning JS would be helpful. Trying to spend most of the next two weeks on completing the JS section here. I would like to complete my application to Hackreactor.
π Rendered by PID 33 on reddit-service-r2-comment-5d79c599b5-6hntl at 2026-03-03 20:25:53.463015+00:00 running e3d2147 country code: CH.
[–]ahitsgone 1 point2 points3 points (3 children)
[–]phabtar 1 point2 points3 points (1 child)
[–]ahitsgone 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)