Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


              <div id="root"></div>




              const UNIT = {
  KPH: 'Км/ч',
  MPH: 'Миль/ч'

// максимальная разрешённая скорость в населённом пункте в км/ч

function SpeedDetector(props) {
  const unit = props.unit;
  if (props.speed >= props.maxSpeed) {
    return <div>Скорость в {UNIT[unit]} превышена!</div>;
  return <div>Скорость в {UNIT[unit]} не превышена.</div>;

function isValidSpeed(value){
  if(value !== null && value !== '' && value !== undefined){
    let intValue = parseInt(value);
    return !(isNaN(intValue) || !isFinite(intValue));
  return false

function convertToKph(mph) {
  return mph * 1.61;

function convertToMph(kph) {
  return kph / 1.61;

function сonvertSpeed(value, convertor) {  
    const intValue = parseInt(value)
    let converted = convertor(intValue);
    let rounded = Math.round(converted * 100) / 100
    return rounded.toString()
  return '';

class SpeedSetter extends React.Component {
  constructor(props) {
    this.onChange = this.onChange.bind(this);

  onChange(e) {

  render() {
    let speed = this.props.speed;
    let unit = this.props.unit;
    return (
        <span>Введите скорость в "{UNIT[unit]}": </span>
        <input value={speed} onChange={this.onChange}/>

class SpeedRadar extends React.Component {
    this.onChangeSpeedInKph = this.onChangeSpeedInKph.bind(this);
    this.onChangeSpeedInMph = this.onChangeSpeedInMph.bind(this);
    this.state = {speed: 0, unit: 'KPH'};
  onChangeSpeedInKph(speed) {
    this.setState({unit: 'KPH', speed});
  onChangeSpeedInMph(speed) {
    this.setState({unit: 'MPH', speed});
  render() {
    const unit = this.state.unit;
    const speed = this.state.speed;
    const kph = unit === 'MPH' ? сonvertSpeed(speed, convertToKph) : speed;
    const mph = unit === 'KPH' ? сonvertSpeed(speed, convertToMph) : speed;

    return (
        <SpeedSetter unit="KPH" speed={kph} onChangeSpeed={this.onChangeSpeedInKph}/>
        <SpeedSetter unit="MPH" speed={mph} onChangeSpeed={this.onChangeSpeedInMph}/> 
        <SpeedDetector speed={kph} unit="KPH" maxSpeed={MAX_SPEED_IN_CITY_IN_KPH}/>

ReactDOM.render(<SpeedRadar />, document.getElementById('root'));