Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSam Weeks
Front End Web Development Techdegree Student 16,699 PointsEverything look okay?
Everything seems to work ok but if anyone has any tips on anything to look out for , feedback much appreciated
thanks!!
var count = 5;
var question = 0;
var firstQuestion = prompt('Hi. here\'s a little quiz I put together using JavaScript there are ' + count + ' questions in total. First Question. What is the color of the sky?');
if(firstQuestion.toUpperCase()==='BLUE'){
question += 1;
count-=1
alert('Yes that\'s the right answer. You have ' + count + ' questions left.');
} else {
count-=1;
alert('That was incorrect. You have ' + count + ' questions left.')
}
var secondQuestion = prompt('How many weeks are there in a Year?');
if(secondQuestion.toUpperCase()==='52') {
question += 1;
count-=1;
alert('Yes that too was correct. You have ' + count + ' questions left.');
} else {
count-=1
alert('Ahh you got that one wrong. That\'s ok try the next one. You have ' + count + ' questions left.');
}
var thirdQuestion = prompt('what is the capital of England?');
if(thirdQuestion.toUpperCase() === 'LONDON'){
question += 1;
count-=1
alert('Bloody hell your good a big pat on the back to you. You have ' + count + ' questions left.')
} else {
count-=1
alert('Never mind we cant get them all right. You have ' + count + ' questions left.')
}
var fourthQuestion = prompt('How many strings does a guitar have');
if(fourthQuestion.toUpperCase()==='6') {
question += 1;
count-=1;
alert('Nice i thought you might have got that one. You have ' + count + ' Question left.')
} else {
count-=1;
alert('That was incorrect, Please try the next question. You have ' + count + ' question left.')
}
var fifthQuestion = prompt('What\'s white and cant clime up trees?');
if(fifthQuestion.toUpperCase()==='A FRIDGE'){
question += 1;
count-=1;
alert('well done you have ' + count + ' questions left click ok to see how you done!!');
} else {
count-=1;
alert('The answer was a Fridge....Never mind well at least you have ' + count + ' questions left. Click ok to continue to your score');
} if(question === 5){
document.write('<h2>Well done you earned a Golden Crown!!</h2>');
} else if (question >= 3){
document.write('<h2>You earned a silver crown well done</h2>');
} else if(question >= 1 ) {
document.write('<h2>You earned a bronze crown</h2>')
} else {
document.write('<h2>You failed the test. please feel free to refresh and try again<h2>')
}
document.write('<h3>Thank you for taking your time to fill out this test. You answered ' + question + ' right. </h3>');
Sam Weeks
Front End Web Development Techdegree Student 16,699 PointsCheers Mike Thanks for taking a look :)
2 Answers
Steven Parker
231,124 PointsCertainly, "work OK" is the most important aspect of a program, by far.
Beyond that, you can make code like this much more compact and easy to read by using functions, but I think that probably has not been covered yet in the course(s). Keep plugging and you'll get there.
Sam Weeks
Front End Web Development Techdegree Student 16,699 Pointsthanks steven. that code you were helping me with yesterday i think i cracked it only half your comments came through yesterday so at first i wasnt following 100% to what you were saying, i had another look this morning the rest of what you put appeared and i came up with this
var correctGuess = false;
var correctGuess_2 = false;
var randomNumber = Math.floor(Math.random() * 6 ) + 1;
var guess = prompt('I am thinking of a number between 1 and 6. What is it?');
if (parseInt(guess) === randomNumber ) {
correctGuess = true;
}
if (correctGuess===true) {
document.write('<p> You guessed the number!</p>')
} else {
alert("That was incorrect try again")
var guess2 = prompt("Second guess attempt");
} if(parseInt(guess2)===randomNumber) {
correctGuess_2 = true;
} if (correctGuess_2) {
document.write('<p>You got it that time!</p>');
}
else if (correctGuess!== true&&correctGuess_2 !== true){
document.write('<p>Sorry. The number was ' + randomNumber + '</p>')
}
Steven Parker
231,124 PointsGood deal, but mixing the answers to 2 questions might be a bit confusing for other readers.
Sam Weeks
Front End Web Development Techdegree Student 16,699 PointsAhh fair enough. I’ll stick o the lessons for a bit longer and then I’ll go back to all my old code. I’m trying to implement code as soon as I have an idea and challenge myself to solve my own problems. The only thing is I never know how long to stay on one subject at the moment. I.e. if the basics is all I should start with on the FE track or I should stick on one segment at a time untill I’ve mastered everything in them. I’ve got the html//css//JavaScript//J-Query books by John duckett as well so I’m interchanging between them and the treehouse courses
Mike Hatch
14,940 PointsSam, those John Duckett books beautifully visualize web development. But do tread lightly as the publishing date I believe is 2014. I really don't think you can "master" something here on Treehouse before you move on. It's better to reinforce (conditionals in this case) with other outside resources later on. One outside resource I like is Wes Bos. The man is on top of everything. Very up to date. Only drawback is he's very fast. Assumes a lot of knowledge when you follow along.
Sam Weeks
Front End Web Development Techdegree Student 16,699 PointsMike Hatch
Thank You im just trying to get to speed with the basics so i can start freelancing for small businesses that dont have websites and eventually either get a job with a company or carry on freelancing. I'm a musician so i would love to be able to travel and work whilst playing music in the evenings. I'll take a look at Wes Bos though, I just want to soak up as much as I can to get a better understanding of how the front end works. I was thinking of doing the Tech-Degree here once ive run through the Front-End track at least twice.
Mike Hatch
14,940 PointsMike Hatch
14,940 PointsWorked perfect for me in Chrome Dev Tools. No errors.