Write a nodejs command-line application that asks for radius and prints out the surface…
- User
Write a nodejs command-line application that asks for radius and prints out the surface area of a sphere of that radius.
Assistant
Sure! Here's a Node.js command-line application that asks for the radius of a sphere and prints out its surface area:
const { readLine } = require('readline'); const rl = readLine.createInterface({ input: process.stdin, output: process.stdout }); rl.setPrompt('Enter radius: '); let radius; rl.on('line', (line) => { radius = parseFloat(line); if (isNaN(radius)) { console.log('Invalid input. Please enter a valid radius.'); rl.setPrompt('Enter radius: '); return; } calculateSurfaceArea(); }); function calculateSurfaceArea() { const surfaceArea = (4 * Math.PI * radius * radius); console.log(`The surface area of the sphere with radius ${radius} is ${surfaceArea}.`); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.