I need help doing something simple with java script.
When I try running it, it doesn't work.
var guess = prompt("Hello");
if (guess === "Hi." ) {
console.log ("Sup.");
else
Can someone help me please? Thanks.
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)
Offline
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
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
Offline
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![]()
Still doesn't work. :S
Oh well. I'll just keep learning more.
Offline
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![]()
Still doesn't work. :S
Oh well. I'll just keep learning more.![]()
it works for me
... what browser do you use? i have Google Chrome 16.0 on Ubuntu.
Offline
I've never even heard of the Console object!
Offline
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.
Offline
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![]()
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
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![]()
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.
Offline
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.)
Offline
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)
Offline