+ 1
What is wrong? Error on test.
7 Answers
+ 1
Apart from the fact that prompt() function does not exist in nodejs, 0 is technically a perfect square and except if it was stated explicitly to ignore zero, i don't think that condition should be there.
it would be safe to consider positive numbers as the only possible numbers and Incase if the testcase has a test for big integers, that condition at line 8 will fail. I would suggest you do something like this
If (sqrt(x) % 1 === 0n)
or in es2020
Number.isInteger(sqrt (x))
note: sqrt is from Math
I'm sure there have to be a faster way for big integer operations too like right shift to 5n >> 5n but that wouldn't be necessary I guess
+ 3
Could you please describe what the code is supposed to do?
According to the error message, we can't use prompt() in the node.js script. If it is a sololearn code task, use the given code to get input.
+ 2
Worked. Thx for all) Prompt - is a title of function:
const prompt = (function() {
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
return function() {
if (lines.length > 0)
return lines.shift()
const error = Error('EOF when reading a line')
error.name = 'EOFError'
throw error
}
})()
+ 1
prompt function doesn't works in Node js
use readLine function
+ 1
let x = Number(prompt())
let y = Number(prompt())
let a = ''
for(x; x <= y; x++){
if (Number.isInteger(Math.sqrt(x))){
a = a + " " + x
}
}
console.log(a)
0
Use Web playground's JavaScript tab for running JS code..
0
This is a task from another course.
Machine translate:
"Input data
Integers a and b are entered. It is guaranteed that a does not exceed b.
Output
Print all numbers on the segment from a to b that are perfect squares. If there are no such numbers, then nothing needs to be output."