+ 2
What is the code for JavaScript basic concept office computers
Sorry I don’t understand the code it gave me
3 ответов
+ 2
Simply multiply the count of the computers by 2
Output your answer to the console log
below the comment type your code.
//your code goes here
console.log( name * value );
What name and value is the question asking for?
+ 1
The first line creates a variable called computers which stores the input value.
var computers = parseInt(readLine(), 10)
It is not entirely necessary to fully understand this line however it is a good idea to have some understanding of it.
parseInt() is a Javascript function that takes in a string, and returns it as an integer.
readLine() will read the input line when the program is run.
the 10 after readLine represents the radix (the base in mathematical numeral systems) which is optional when using parseInt.
for example:
lets say our input is "10" (note the quotes means its a string)
the variable (var) computers equals parseInt(readLine(), 10)
so we read the input (readLine()) as "10" (a string) and return it as an integer (parseInt()) 10. As a result, the variable computers now equals 10.
we are asked to return the number of monitors in the console, given each computer has 2 monitors. To do this we multiply each computer by 2.
first off we use console.log() to output the result to the console.
next we take our total number of computer, which is stored in the variable 'computers' and put that between the parenthesis to tell the compiler what we want to output. That will look something like this.
console.log(computers)
however we want the total number of monitors, we have been told that each computer has 2. So we want to multiply the variable computers by 2 using the * (multiplication) operator.
So now our code should look like this
console.log(computers * 2)
I hope this helps you understand the code a bit better
0
Thanks