# Seek-Help!

### nnguyen52 γ»2 min read

hi everyone and have a nice day!

im pretty new to javascript as well as propramming. (been for only 1 month)

## im practicing this question (im NOT allowed to use if-then operator as teacher's assignment):

Here is a sample:

first: Q. I made 26 cupcakes and ate 15 of them. How many am I left with?

A. 11

second: The next time the page loads, the numbers should change, so the problem may look like:

Q. I made 45 cupcakes and ate 2 of them. How many am I left with?

A. 43

third: The numbers used in this word problem should change randomly. This means

that we need to generate the numbers for the questions and the answer using

JavaScript.

HINT: you will need to use the Math.random() method to complete this part.

Here are the characteristics of the problem along with the possibilities you need to consider:

- The generated random numbers should always be between 0 and 50.
- You should never encounter a scenario in which you make less cupcakes and eat more. For example: Q: I made 45 cupcakes and ate 47 of them. How many am I left with?
- In case you donβt eat any cupcakes, the question should say: Q: I made 45 cupcakes and ate none of them. How many am I left with? instead of saying Q: I made 45 cupcakes and ate 0 of them. How many am I left with? and the answer should say: A. I don't need to do any calculations.

## + You are not allowed to use the ifβ¦then construct.

This is my code (i still have errors and issues):

var made= Math.floor(Math.random() * 50) + 1;

var eat = Math.floor(Math.random() * 50) + 0;

let b= (eat== 0? "none" : eat);

console.log ("Q. I made " + (made== 1? "1 cupcake": made + " cupcakes") + " and ate " + b + " of them. How many am i left with?");

console.log ("A: " + (b== "none"?"I don't need to do any calculations.": (0 <= eat < made <= 50, made-eat)));

document.write ("Q. I made " + (made== 1? "1 cupcake": made + " cupcakes") + " and ate " + b + " of them. How many am i left with?" + "<br>");

document.write ("A: " +(b== "none"? "I don't need to do any calculations.": (0 <= eat < made <= 50, made-eat)) );

Hi, maybe I can help, you can check the live version here codesandbox

Using a

`while`

loop to generate a number of eaten cupcakes smaller than the amount made is unnecessary, it's better to generate the amount of cupcakes and then use that number as the ceiling for the amount of eaten cupcakes.Yes it's make sense to use start-end range for eaten and or made cakes and should be better.

Already updated my code on sandboxHi Sir, i checked the code you guided me, it seems not working somehow. and im just getting to While-operation and i have not known about $, then i got confused. can you make it simplified ?

It's "template literal string in javascript" if you want to look at it. But you can simply change with + for join string like this: