# Practice Exercises - console.log & Variables

Hello,

I am doing my exercises and I have a small problem. For the exercise no. 8 I wrote the code like this and the result was the one that I expected.
https://gyazo.com/fdb88c486d454ea92f0fce85209e5a66

The solution gave me this result https://gyazo.com/9faac5bf20b833a5417791836dfc10fa

Can you explain if I did something wrong or what is the solution about?

Thank you

3 Likes

Hi there,

I was faced with a similiar problem and found out that in order for \${} to work, the whole statement has to be inside of quotes that look like ``.

I cannot find the shortcut for those quotes on my keyboard so i have to always copy paste them. Can someone please explain how to find the right shortcut for this quotes on my keyboard?

Thanks

3 Likes

Oh, get it now! yeah with those it works. The shortcut for the quotes `` is just the to press the first key that is next to â1â. It also makes this mark when you press also âshiftâ: ~ .
Thank you very much and have a great day!

3 Likes

I found them! I was having my keyboard set to qwertz instead of qwerty and now i can press it Â´Â´ `` ^^ yeah!!

1 Like

Hei,

I have another question if itâs not too much. At the exercise no.16, the one with the shopping list I made this program :

``````      var bread = 2;
var milk = 1.5;
var cheese = 4;
var yogurt = 1.2;
console.log("Hi! Welcome to the Ivan on Tech shop!");
console.log ("How much bread do you want?");
var quantMilk = prompt("How much milk do you want?");
console.log ("How much milk do you want?");
console.log (quantMilk);
var quantcheese = prompt("How much cheese do you want?");
console.log ("How much cheese do you want?");
console.log (quantcheese);
var quantyogurt = prompt("How much yogurt do you want?");
console.log ("How much yogurt do you want?");
console.log (quantyogurt);
console.log("The total amount to pay is ", totalamount);
``````

But the solution is different from the one I thought about. The resullts are the same for the both of them, but I want to know for sure if the code I wrote is ok too.

3 Likes

Well, honestly i just started exploring and learning about coding also, so i am not maybe the best person to review your code and say if it is good or not its, working and for beginning that is a good sign But if i can comment the code, i would say the console.log are to many, as only the last one, which prints the total amount to the console, is required. By removing these, the code will immediately look cleaner.

In regards to the solution, mine code is also not always similar to the presented solution, but in my opinion if you can understand and read the given solutions and learn from that as to what you could improve on your side, or what is maybe better on your side, this is what matters. We are here to learn

Best,
Peter

1 Like

All the best!

1 Like

Yea that would work this is how i didâŚ excuses my language it was late last nightâŚlol

var milk = Number(prompt(âThis is Dans sht\nGot Milk?"));
if (!Number.isNaN(milk)) {
console.log(milk * 1.5);
} else {
console.log(âHow Much Milk You Want Fool?â);
}
var bread = Number(prompt("This is Dans sh

var cheese = Number(prompt(âThis is Dans sht\nShould I Throw Some Cheese On Dat Btch?â));
console.log(cheese * 4);

var yogurt = Number(prompt(âThis is Dans sh*t\nYou Messin Wit Dat Gurtâ));
if (!Number.isNaN(yogurt)) {
console.log(yogurt * 1.2);
} else {
console.log(âTalkin Bout Dat Yogurt, I pitty a Fool!â);

if (!Number.isNaN()) {
console.log(alert(" Come On Now, Enter a Number Amount!"));}
}

I donât know who i should let know about this but one of the Achademyâs code is not working properly in the solutions for exercise #16. There should be no âsâ in Yogurt"s" at the bottom of the code. Itâs giving a Undefined response in the console for Yogurt.

var milk = 1.5 ;
var cheese = 4 ;
var yogurt = 1.2 ;
var sum = 0 ;
alert( âHi! Welcome to the Ivan on Tech Shop!â );
var input = prompt( âHow much bread do you want?â );
var input = prompt( âHow much milk (liter) do you want?â );
sum += input * milk;
var input = prompt( âHow much cheese do you wantâ );
sum += input * cheese;
var input = prompt( âHow many yogurts do you want?â );
sum += input * yogurts;
console .log( âThe total amount to pay isâ , sum);

1 Like

For me is working. I mean, yeah, is a typo mistake, but if you delete the âsâ from â yogurtsâ itâs working.

1 Like

Like @carmen1408 picked out, you need to remove âsâ from your â`yogurts`â variable as you defined â`yogurt`â and not â`yogurts`â.

Happy Learning!

3 Likes

Ok so im completely lost here. The instructions tell us to create a file and save it in js format but when i do that i cant bring it up in fire fox so what ive been doing is just opening up the console in a random page and doing the excersizes there, i havnt been able to save them and im worried because i think we may have to build on these in lessons that follow. I dont know if atom has a console in it or how to use it. Why are they asking us to save it in js format? I guess i just need help using atom but specifically bringing up the console in atom and saving in js file format

1 Like

I think they said to save it in js format so we know what problem it is and not to write a line of code in the console at a time and to copy-paste all program in the console when itâs done.

So we write it in java and copy it into the console, got it. I guesse the point is for us to learn the excersize and its not like were going to turn it in or use it in future lessons.

I am not sure. That is what I think. @Malik should tell us for sure.

Hi @Moneymonty and @carmen1408,

Hope youâre having a great day.

You wonât see console logs in your atom console. The only way you can see it is if you run a local node server and console log through it which is out of the scope of this course.

If you have your js file with all your javascript code, you need to place it in a HTML file and then open the HTML file in your browser. Thus, no matter how big your Javascript code is, we can see all the outputs on the chrome console.

Find below code for reference

My HTML â

``````<html>

<title>This example of using form to add item to array comes from IvanOnTech JS course.</title>

<body>

<h1>My favorite fruits</h1>

<ol class="fruitList">
</ol>
</body>

</html>
``````

My JS file (myJscode.js) â

``````const listValues = [120, 4, 9, 7, 2, 8, 3, 1, 1100];
var lowestValue = listValues[0];
var highestValue = listValues[0];
// console.log(lowestValue)
for (num in listValues) {
num = Number.parseInt(num)
if (listValues[num] < lowestValue) {
lowestValue = listValues[num]
}
}
console.log(lowestValue)

for (num in listValues) {
num = Number.parseInt(num)
if (listValues[num] > highestValue) {
highestValue = listValues[num]
}

}
console.log(highestValue)
``````

So, the conclusion is, no matter how big the project, in the end, we always inject our JS code into the HTML code for the browser to read it and execute it. The only way we can execute JS files outside of HTML and browser is through a node server instance (you will learn it in advance courses).

Hope this helps. Happy Learning!

2 Likes

Man i was way off on that 1. I forgot u csn use to actually put kava in the html code. Can u imagine trying to do these assignments without knowing that? Lol

I need help please: itâs Question 14: " Text printing with formatting .

1. Write a script that contains three different cryptocurrencies contained in three different variables.
2. Print the cryptocurrencies in 3 different lines."

I want to console to look like this:
Bitcoin
Ethereum
Tezos

I CAN NOT SEEM TO GET THE F***ING CODE TO WORK AND GO INTO A NEW LINE. WHAT AM I DOING WRONG?

This is what Iâve got:
var BTC = âBitcoinâ
var ETH = âEthereumâ
var XTZ = âTezosâ

console.log(BTC, \nETH, \nXTZ);

If I put the variables into inverted commas it works, but then it returns the actual tickers (the variable names, not the values of the variables)

1 Like

Hello @Marcelle, hope you are great.

You can use the âPreformatted Textâ Button to encapsulate any kind of code you want to show.

``````
function formatText(){

let words = âIâm a preformatted Text box, Please use me wisely!â

}

``````

Carlos Z.

1 Like

var BTC = âBitcoinâ
var ETH = âEthereumâ
var XTZ = âTezosâ

console.log(BTC + \nETH + \nXTZ);

1 Like