Let me show you:
var x =
var y =
//The ternary operator in action
result = x > y ? "good job" : 20;
//Rewrite the ternary code using if else statements
First I tried to use return, but that gave me some error messages, but then I tried this and it worked, but I didn't pass the lesson:
if (x>y){
console.log("good job");
}else{
console.log(20);
}
See the 'result' in the ternary operator? Turns out you need that instead of anything else, because; they feel like it.
That's stupid. I understand using result, but they could have told me that....
And Now I'm doing a dice game and using math.
var die1 = Math.floor(Math.random()*6 + 1);
Math.Whoever created the math section in .js is hilarious!
Today's post is brought to us by a nice latté and some Electric Light Orchestra. Time to plug in atd plug away!
I just got ridiculously happy, because; I finished a lesson with no errors and passed at the very first try! WHOO!!
One of the really cool things that I like about having a forum, is that I can see how other people wrote their answers, and how they are different from mine.
For instance, this is mine:
// here we need to check if there are doubles. If so, score should be
// double the sum of the two dice
if(die1+die2%2===0){
score=(2*(die1+die2));
}else{
score=(die1+die2);
}
}
and this is someone else's:
// here we need to check if there are doubles. If so, score should be
// double the sum of the two dice
if(die1===die2){
score=(die1+die2)*2;
}
else{
score=die1+die2;
}
}
Personally speaking, I like what they did with the <if (die1===die2)> better than my <if (die1+die2%2===0)> their's is so much more simple! I should have thought of that...
Simplicity is what I'm trying to go for every time I write code. So, I'm now upset that I didn't do a better job at it. Oh well, next time I'll know.
Hopefully, they won't split each test into something like this: // Define a function named calculateTotalCosts
// declare a variable fixedCosts the value of 5000
// have the function return fixedCosts
I can do that easily. why not have the text three things in the same page?
Ah well. See y'all Monday!
--Martin
No comments:
Post a Comment