0

I don't want to run the Python code inside Javascript, I want to turn it completely into JS code. I have no idea about python, Can body can help me on this. Thank you.

print ("Please input the # of books you've read this year") 
BooksAlready=int(input())
print ("Please input the # of weeks that have already passed this year") 
WeeksAlready=int(input())
x=(78/52)
c=x*WeeksAlready-BooksAlready
if (BooksAlready/WeeksAlready)>x:
  print ("You're on point, go have some fun!")
else:
  print ("Go read, you piece of uneducated crap")
  print ("You have")
  print (c)
  print ("books left to read this week to get on point")
Cfreak
  • 19,191
  • 6
  • 49
  • 60
Gold Pearl
  • 13
  • 1
  • 5
  • Presumably you want this to run in a terminal like NodeJS? – Alexander Nied Mar 29 '17 at 04:45
  • 1
    Possible duplicate of [Python to Javascript converter](http://stackoverflow.com/questions/22595989/python-to-javascript-converter) – Harsha W Mar 29 '17 at 04:45
  • 1
    This might help you-http://stackoverflow.com/questions/22595989/python-to-javascript-converter – Mamun Mar 29 '17 at 04:47
  • If you just need it to run in a JS environment, apparently [some tools do exist](https://www.npmjs.com/package/python-js) -- although I'm a bit dubious of cross-language transpilation. Or is this an exercise-- where you want to do it to learn about Python? – Alexander Nied Mar 29 '17 at 04:47
  • @anied yes I want to run this in JS environment. I want to convert into pure Js – Gold Pearl Mar 29 '17 at 04:51
  • Do you want it to run in the browser, or server-side with NodeJS? *"Go read, you piece of uneducated crap"* - That's a bit harsh. – nnnnnn Mar 29 '17 at 04:54

2 Answers2

1

This will run in the browser's js console. prompt will not work in node.js, you can access a commandline argument with process.argv.

console.log("Please input the # of books you've read this year");
console.log("Please input the # of weeks that have already passed this year");

var WeeksAlready=parseInt(prompt()),
BooksAlready=parseInt(prompt()), 
x=(78/52),
c=x*WeeksAlready-BooksAlready;

if (BooksAlready/WeeksAlready>x){
    console.log("You're on point, go have some fun!");
}
else{
   console.log ("Go read, you piece of uneducated crap");
   console.log ("You have");
   console.log (c);
   console.log ("books left to read this week to get on point"); 
}
nick
  • 1,197
  • 11
  • 16
0

Please check below links to know more about converters from python to js.

http://www.infoworld.com/article/3033047/javascript/4-tools-to-convert-python-to-javascript-and-back-again.html

Mohammed Rishad
  • 225
  • 3
  • 6