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 an example of a Node.js command-line application that asks for the radius and prints out the surface area of a sphere:
const prompt = require('prompt'); prompt.start(); // Prompt user for radius prompt.get(['radius'], (err, result) => { if (err) { console.error(err); process.exit(1); } const radius = result.radius; // Calculate surface area of sphere const surfaceArea = 4 * Math.PI * radius ** 2; console.log(`The surface area of a sphere with radius ${radius} is ${surfaceArea}`); });This application uses the
promptmodule to prompt the user for the radius, and then uses theMath.PIconstant and the power operator to calculate the surface area of the sphere. Finally, it logs the result to the console.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.