Assesment for Conditional 2 Test

Hi there, i just tried to solve Conditional 2 test on MDN Site

i tried to solve but im stuck again. Pls help

here is the Link to Codepen:

Thx in Advance. Regards

This isquite a tricky one; see the marking guide at

Hi Chris,
the Conditional 2 Test is About scores and responses. Must be an other solution.

Conditionals 2 Test

My Code is as follows:

Code in Codepen

Thx for your help :slight_smile:

Nope, that’s the correct solution; click on the link through to the correct section of the page. What it is showing in this thread is not the correct bit.

Anyway, your code seemed to work ok, although I had to change it slightly so that the else part of the top level block works:

if(machineActive) {
  if(score < 0 || score > 100) {
    response = 'This is not possible, an error has occured.';
  } else if(score <= 19) {
    response = 'That was a terrible score — total fail!';
  } else if(score <= 39) {
    response = 'You know some things, but it\'s a pretty bad score. Needs improvement';
  } else if(score <= 69) {
    response = 'You did a passable job, not bad!';
  } else if(score <= 89) {
    response = 'That\'s a great score, you really know your stuff';
  } else if(score <= 100) {
    response = 'What an amazing score! Did you cheat? Are you for real?';
  } 
} else {
  response = 'The machine is turned off. Turn it on to process your score.';
}

But other than that, you are going in the right direction.

2 Likes

Nice. Didnt expect that it was that correct. Can you please tell me further, why variable para2 says undefined in my codepen Code ?.

Your score is 75 ----> this is para1
undefined ---->this is para2

Doesnt it has to say ‘The machine is turned off. Turn it on to process your score’ ?

Hi Chris,
please can you help me if its ok .
let response;
let score = 75;
let machineActive = false;

// Add your code here
if(machineActive) {
if(score < 0 || score > 100) {
response = ‘This is not possible, an error has occurred.’;
} else if(score <= 19) {
response = ‘That was a terrible score — total fail!’;
} else if(score <= 39) {
response = ‘You know some things, but it’s a pretty bad score. Needs improvement.’;
} else if(score <= 69) {
response = ‘You did a passable job, not bad!’;
} else if(score <= 89) {
response = ‘That’s a great score, you really know your stuff.’;
} else if(score <= 100) {
response = ‘What an amazing score! Did you cheat? Are you for real?’;
}
} else {
respone = ‘if the machine is turned on.Turn it on to process your score.’;
}

section.innerHTML = ’ ';
let para1 = document.createElement(‘p’);
let para2 = document.createElement(‘p’);

para1.textContent = Your score is ${ score };
para2.textContent = response;

section.appendChild(para1);
section.appendChild(para2);

Hi @Suad_Zetounie, thanks for sending in your code!

So, I’m just marking the bit under “Add your code here”; you didn’t need to touch the rest of the code, although I’ve seen there are a few changes in other places.

I had to make a couple of changes before the code worked, but this was mostly fine; well done on a good try here.

The final code looks like this:

if(machineActive) {
  if(score < 0 || score > 100) {
    response = 'This is not possible, an error has occurred.';
  } else if(score <= 19) {
    response = 'That was a terrible score — total fail!';
  } else if(score <= 39) {
    response = 'You know some things, but it\'s a pretty bad score. Needs improvement.';
  } else if(score <= 69) {
    response = 'You did a passable job, not bad!';
  } else if(score <= 89) {
    response = 'That\'s a great score, you really know your stuff.';
  } else if(score <= 100) {
    response = 'What an amazing score! Did you cheat? Are you for real?';
  }
} else {
  response = 'Turn the machine on to process your score.';
}

The changes:

  1. I put a backslash (\) before each of the single quites include inside the response strings — you need to do this otherwise the browser will think this is where you want to end the wring, and you’ll get errors.
  2. You had a typo — the last instance of response was spelt respone

I also indented the code to make it easier to read and understand.

Well done, and best of luck with future coding.

1 Like