create a page in svelt that calculates in the planets gravity-pull newtoans in javascript

Here's a basic example of how to create a Svelte page that calculates the weight of an object on different planets based on their respective gravity:

<template>
  <div>
    <h1>Planet Gravity Calculator</h1>
    <input type="number" bind:value={weight} placeholder="Enter object weight (lbs)">
    <div class="planets">
      <div class="planet" each={planet in planets}>
        <h2>{planet.name}</h2>
        <p>Weight: {calculateWeight(planet.gravity)}</p>
      </div>
    </div>
  </div>
</template>

<script>
  const planets = [
    { name: 'Mercury', gravity: 3.7 },
    { name: 'Venus', gravity: 8.87 },
    { name: 'Earth', gravity: 9.81 },
    { name: 'Mars', gravity: 3.711 },
    { name: 'Jupiter', gravity: 24.79 },
    { name: 'Saturn', gravity: 10.44 },
    { name: 'Uranus', gravity: 8.69 },
    { name: 'Neptune', gravity: 11.15 },
    { name: 'Pluto', gravity: 0.62 },
  ];
  
  let weight = 0;
  
  function calculateWeight(gravity) {
    const weightOnEarth = weight / 2.20462;
    const weightOnPlanet = weightOnEarth * gravity;
    const weightInNewtons = (weightOnPlanet * 4.44822162).toFixed(2);
    return `${weightInNewtons} N`;
  }
</script>

<style>
  .planets {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  
  .planet {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background-color: #A8A8A8;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 1rem;
  }
  
  h2, p {
    margin: 0;
  }
</style>
1392 chars
60 lines

In this example, we have an array of planets with their respective gravity values. We also have an input field for the user to enter the weight of the object they want to calculate the weight for. The calculateWeight() function takes the gravity of the planet and calculates the weight of the object on that planet in newtons, using the formula force = mass x gravity. The weight is then displayed on the page for each planet in newtons.

gistlibby LogSnag