This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-10 19:21:38

Solarbuddy
Scratcher
Registered: 2009-04-14
Posts: 500+

Java Script Help. :S

I need help doing something simple with java script.  hmm
When I try running it, it doesn't work.  hmm

var guess = prompt("Hello");

if (guess === "Hi." ) {
console.log ("Sup.");
else

Can someone help me please? Thanks.  big_smile
I'm learning java script, and that's a random thing I thought up from learning from a lesson.

Last edited by Solarbuddy (2012-01-10 19:24:23)


http://bit.ly/Vn3zid
                  View my latest project

Offline

 

#2 2012-01-10 19:32:26

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: Java Script Help. :S

I dont know. I know a lot of js, but I never messed around with the console object.


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#3 2012-01-10 19:41:45

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Java Script Help. :S

Er... You forgot to put an action for else

anyways...

var guess = prompt("Hello");

if (guess === "Hi." ) {
console.log("Sup.");
}

If you want to add an else, you could do something like:

var guess = prompt("Hello");

if (guess === "Hi." ) {
console.log("Sup.");
}
else {
console.log("You didn't say hi to me!!!");
}

Offline

 

#4 2012-01-10 19:56:55

Solarbuddy
Scratcher
Registered: 2009-04-14
Posts: 500+

Re: Java Script Help. :S

Still doesn't work.  hmm
Oh well.  big_smile


http://bit.ly/Vn3zid
                  View my latest project

Offline

 

#5 2012-01-10 20:03:29

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Java Script Help. :S

Does it say it can't find the console object? Some browsers don't support it.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#6 2012-01-10 20:16:30

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Java Script Help. :S

Code:

var guess = prompt('Hello');
if (guess == 'Hi.' ) {
console.log('Sup.');
}

the code above works for me. i think the problem was that you used double quotes instead of single quotes... and maybe also because there was three equals signs instead of two.

i type Hi. and open the console... magic... the text "Sup." appears  tongue


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#7 2012-01-10 22:22:02

Solarbuddy
Scratcher
Registered: 2009-04-14
Posts: 500+

Re: Java Script Help. :S

nathanprocks wrote:

Code:

var guess = prompt('Hello');
if (guess == 'Hi.' ) {
console.log('Sup.');
}

the code above works for me. i think the problem was that you used double quotes instead of single quotes... and maybe also because there was three equals signs instead of two.

i type Hi. and open the console... magic... the text "Sup." appears  tongue

Still doesn't work. :S
Oh well. I'll just keep learning more.  big_smile


http://bit.ly/Vn3zid
                  View my latest project

Offline

 

#8 2012-01-10 22:23:59

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Java Script Help. :S

Solarbuddy wrote:

nathanprocks wrote:

Code:

var guess = prompt('Hello');
if (guess == 'Hi.' ) {
console.log('Sup.');
}

the code above works for me. i think the problem was that you used double quotes instead of single quotes... and maybe also because there was three equals signs instead of two.

i type Hi. and open the console... magic... the text "Sup." appears  tongue

Still doesn't work. :S
Oh well. I'll just keep learning more.  big_smile

it works for me  sad ... what browser do you use? i have Google Chrome 16.0 on Ubuntu.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#9 2012-01-10 22:49:35

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Java Script Help. :S

I've never even heard of the Console object!

Offline

 

#10 2012-01-10 23:07:53

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Java Script Help. :S

scimonster wrote:

I've never even heard of the Console object!

i haven't either but i figured that if you press F12 in Chrome to access developer tools, it has a console. console.log outputs text to the console window.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#11 2012-01-10 23:14:49

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Java Script Help. :S

nathanprocks wrote:

Code:

var guess = prompt('Hello');
if (guess == 'Hi.' ) {
console.log('Sup.');
}

the code above works for me. i think the problem was that you used double quotes instead of single quotes... and maybe also because there was three equals signs instead of two.

i type Hi. and open the console... magic... the text "Sup." appears  tongue

triple equals is the same function as double (checking if two values are equal)

EDT: I'm using the codeacademy scratch pad and this code worked for me:
var guess = prompt("Hello");

if (guess === "Hi." ) {
console.log("Sup.");
}

Last edited by kayybee (2012-01-10 23:16:11)

Offline

 

#12 2012-01-11 08:25:16

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Java Script Help. :S

kayybee wrote:

nathanprocks wrote:

Code:

var guess = prompt('Hello');
if (guess == 'Hi.' ) {
console.log('Sup.');
}

the code above works for me. i think the problem was that you used double quotes instead of single quotes... and maybe also because there was three equals signs instead of two.

i type Hi. and open the console... magic... the text "Sup." appears  tongue

triple equals is the same function as double (checking if two values are equal)

EDT: I'm using the codeacademy scratch pad and this code worked for me:
var guess = prompt("Hello");

if (guess === "Hi." ) {
console.log("Sup.");
}

It only works if you're using codeacadamy or if you have the console up by using firebug or chrome.


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#13 2012-01-11 09:26:43

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Java Script Help. :S

MathWizz wrote:

Does it say it can't find the console object? Some browsers don't support it.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#14 2012-01-11 10:45:57

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Java Script Help. :S

kayybee wrote:

triple equals is the same function as double (checking if two values are equal)

Actually, no it's not. triple equals also checks if the two things you are comparing are of the same type (boolean, string etc.)


http://i.imgur.com/zeIZW.png

Offline

 

#15 2012-01-11 16:13:05

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Java Script Help. :S

kayybee wrote:

triple equals is the same function as double (checking if two values are equal)

triple equals (===) is the identity operator. It simply checks if two objects are identical (the same object)
double equals (==) is the equality operator. It does type coercion before it compares its operands; for example, '0' == 0 (equality), but '0' !== 0 (identity)

Last edited by nXIII (2012-01-11 16:13:21)


nXIII

Offline

 

Board footer