This forum is now read-only. Please use our new forums at discuss.codecademy.com.

723 points
D2958435f830214215d41949d9d0b1d9?s=140&d=retro
Submitted by
Amelia Payne
almost 5 years ago

please help with my project thanks need help by fryday

hi im trying to make a program that i can show at my exibition on fryday its a big deal that i get it done. im tryeing to creat a question constructure than use it to make a quiz game thanks so mutch

//confirm("Are you ready to play");

function ask (question, answer){
//asks question and saves value to a varible
this.userAnswer = prompt(question);
//the correct answer
this.Answer = answer;
//checks to see if the griven answer is correct
this.call = function(){
isRight(this["userAnswer"], this["Answer"]);
};
}
// checks to see if ansr is correct ans console.logs responce
function isRight(userAnswer, answer ){
if (userAnswer === answer){
console.log("correct");
}
else{
console.log("your answer is not correct");
}
}
//trying to test it
var i = new ask("is my name amelia", "yes");


1 vote

permalink

******Friday

454 points
D21e0b7e71046f2db5e3918762c7b2c8?s=140&d=retro
Submitted by
Quraiishi
almost 5 years ago


0 votes

permalink

Not sure about your overall design of your project. One problem I see right away is that the call method is not getting called anywhere. So nothing will get printed out. I am just getting into javascript. So let me go at this in a procedural way

function ask (question, answer){
        //asks question and saves value to a varible
        var userAnswer = prompt(question);
        //checks to see if the griven answer is correct
        if (userAnswer === answer){
            console.log("correct");
        }
        else{
            console.log("your answer is not correct");
        }
}
//trying to test it
var i = new ask("is my name amelia", "yes");

But of course this is only "a" way. Depending on what you are trying to achieve there must be more elegant ways.

443 points
Da1ce7b124544c673ed2f1a780d009ce?s=140&d=retro
Submitted by
drego
almost 5 years ago

2 Comments

D2958435f830214215d41949d9d0b1d9?s=140&d=retro Amelia Payne almost 5 years ago

thanks you are a total life saver. what im trying to do is creat a basic trivia game becuse i have to give a presentation on java script on fryday and i want to give a example of what you can program with it

D2958435f830214215d41949d9d0b1d9?s=140&d=retro Amelia Payne almost 5 years ago

i'll poast the code when im done so you can see what i did


0 votes

permalink

confirm("Are you ready to play harry potter / my project trivia");
var houseState = "you do not have a house";
var houseChoice = Math.random();
if (houseChoice <= 0.25){
houseChoice = "slithrin";
houseState = " would you like to join the deatheaters now and just get it out of the way";
}else if (houseChoice <= 0.50){
houseChoice = "griffendor";
houseState = " you are so brave";
}
else if(houseChoice <= 0.75){
houseChoice = "ravenclaw";
houseState = " you must be so smart";
}
else{
houseChoice = "huffelpuff";
houseState = " have you ever herd that story about the tortise and the hare";
}
var total = 0;

alert("you are in " + houseChoice + houseState);

function ask (question, answer){
//asks question and saves value to a varible
var userAnswer = prompt(question).toUpperCase();
//checks to see if the griven answer is correct

    if (userAnswer === answer.toUpperCase()){
        alert("correct you get 10 points for " + houseChoice);
        total += 10;
    }
    else{
        alert("your answer is not correct minous 5 points from " + houseChoice + " the correct answer was " + answer);
        total -= 5;
    }

}

var snake = new ask("what giant bord game did harry potter have to play to get to get the sorcers stone", "chess");

var frensey = new ask("true or false a centor called bane rescued harry from the enchanted forest", "false");
var horcrux = new ask("what was the first horcrux destroyed", "the diary");
var internship = new ask ("was my internship at UVM or MVS", "UVM");
var mycelium = new ask ("what are mushrooms roots called", "mycelium");
var RAD = new ask ("what dose RAD stand for", "rape aggression defense");
var ginny = new ask ("true or false snape and dracko malfoy were manuplateing nevel longbottom into opening the chamber of secrets", "false");
var girlfriend = new ask("who was harry potters first girlfrend","cho chang");
var married = new ask("who did ron weasley marry", "Hermione granger");
var destroy = new ask ("true or false a sord soaked in basilix veom can kill horcruxes", "true");
var hidrocarbon = new ask ("what is a molcue that is made out of hidrogen and carbon called", "hidrocarbon");
var rad = new ask ("true or false rad is a marshal art", "false");
var dracko = new ask("what dose dracko malfoys first name meen in latan", "dragon");
var coffy = new ask("true or false java script is a coffy drink that people in hollywood love", "false");
var snape = new ask("true or false sevrouse snape is a deatheater in the end", "false");
var lung = new ask("true or false a pulmanary reacherch lab studdys the heart", "false");
var oil = new ask("do deasol and water mix", "no");

var ifWin = function(){
if(total > 30){
alert("You Win!!! you have " + total + " points");
}
else{
alert("You Luse!!! you have " + total + " points");
}
};
ifWin();

723 points
D2958435f830214215d41949d9d0b1d9?s=140&d=retro
Submitted by
Amelia Payne
almost 5 years ago


0 votes

permalink

In the code above I notice a couple of things:

  1. You want to convert the player's answer to uppercase while all the answers you are sending are lower case.
  2. You are creating various variables that you don't use like for instance test. ifWin has been created. But IMHO you could have called the if stmt directly. From what I understand the main use of function is so that you can reuse code that you need in more than one place

443 points
Da1ce7b124544c673ed2f1a780d009ce?s=140&d=retro
Submitted by
drego
almost 5 years ago

2 Comments

D2958435f830214215d41949d9d0b1d9?s=140&d=retro Amelia Payne almost 5 years ago

1 good point
2 what dose IMHO and stmt stand for.
luckly my current code runs for fryday's presentation

Da1ce7b124544c673ed2f1a780d009ce?s=140&d=retro drego almost 5 years ago

in my humble opinion and statement. Sorry about that :)