wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (index = 23)
if (index == 23)
Use ==.
C++
UPDATE users SET id='output' WHERE role=80
UPDATE users SET id='output' WHERE role=80;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
if (data = 7) {{}}
if (data === 7) {{}}
Use === for equality.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let result = 65; result += 1;
let mut result = 65; result += 1;
Need mut to modify.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($temp = 18) {{}}
if ($temp -eq 18) {{}}
Use -eq.
PowerShell
print 'result'
print('result')
print needs parentheses.
Python
'54' + 33
54 + 33
Avoid string coercion.
JavaScript
for (result in list)
for (result of list)
for...in iterates keys.
JavaScript
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
if x = 25
if x == 25
Use ==.
Go
<br></br>
<br>
Self-closing.
HTML
if (bar = 12)
if (bar == 12)
Use ==.
C++
'world' + 69
'world' + 69.to_s
Convert int.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
26y = 10
y26 = 10
Variable cannot start with digit.
Python
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
let v=vec![89,78,44]; let head=&v[0]; v.push(35);
let mut v=vec![89,78,44]; let head=v[0]; v.push(35);
Copy instead of reference.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
assert b > 12
assert b > 12
Correct.
Python
var x int
var x int
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar = 'hello'
let bar = "hello"
Double quotes.
Swift
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if (bar = 56)
if (bar == 56)
Use ==.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
if (item = 41)
if (item == 41)
Use ==.
R
if num > 34 print('message')
if num > 34: print('message')
Colon missing after if.
Python
my @arr = (15,14,94);
my @arr = (15,14,94);
Correct.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for c in range(92) print(c)
for c in range(92): print(c)
Colon after for.
Python
function test(c:string){{return c;}} test(74);
function test(c:string){{return c;}} test('test');
Pass correct type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
{{"id":"result" "name":99}}
{{"id":"result", "name":99}}
Add comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if y = 74
if y == 74
Use ==.
MATLAB
let item: Int = 'result'
let item: String = 'result'
Fix type.
Swift
print 'hello'
print 'hello';
Add semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
echo 'info'
echo 'info';
Add semicolon.
PHP
[33, 72, 3
[33, 72, 3]
Close bracket.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
let mut index=65; let ref1=&mut index; let ref2=&mut index;
let mut index=65; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
val item = 'value'
val item = "value"
Double quotes.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
arr[10]
if arr.indices.contains(10) {{ arr[10] }}
Check index.
Swift
yield x
yield x
Correct yield.
Python
fn render() -> i32 {{ 42 }}
fn render() -> i32 {{ 42 }}
Correct.
Rust
if (item = 63) {{}}
if (item == 63) {{}}
Use ==.
Kotlin
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
for i=1,44 do print(i) end
for i=1,44 do print(i) end
Correct.
Lua
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
List(47,37,78)
List(47,37,78)
Correct.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<user><desc>world</desc><age>56</age></user
<user><desc>world</desc><age>56</age></user>
Add closing >.
XML
while x > 23 x -= 1
while x > 23: x -= 1
Colon missing after while.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
if (val = 66) {}
if (val == 66) {}
Use ==.
Dart
process
process()
Add parentheses.
Swift
arr[13]
if (length(arr) >= 13) arr[13]
Check length.
R
const temp = 15; temp = 41;
let temp = 15; temp = 41;
Cannot reassign const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
int values[55]; values[55]=5;
int values[55]; if(55<55){{}} else values[55]=5;
Bounds check.
C++
$list[7]
if ($list.Count -gt 7) {{ $list[7] }}
Check bounds.
PowerShell
if result = 33
if result == 33
Use ==.
Ruby
items(73)
if length(items) >= 73, items(73), end
Check length.
MATLAB
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
let b: number | null = null; b.toFixed(24);
let b: number | null = null; if(b!==null) b.toFixed(24);
Null check.
TypeScript
re.sqrt(98)
import re re.sqrt(98)
Import module first.
Python
'result' + 73
'result' + str(73)
Can't add int to string.
Python
switch(index){{ case 38: break; }}
switch(index){{ case 38: break; default: break; }}
Add default case.
Java
if [ $foo = 37 ]; then
if [ "$foo" = 37 ]; then
Quote variable.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Item def method end end
class Item def method end end
Correct.
Ruby
a = result
a = 'result'
Quote strings.
Python
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($z = 97) {{}}
if ($z -eq 97) {{}}
Use -eq.
PowerShell
if temp = 9 then print('test') end
if temp == 9 then print('test') end
Use ==.
Lua
val item = 62; item = 85
var item = 62; item = 85
Use var for reassignment.
Scala
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
list[20]
if (list.indices.contains(20)) list[20]
Check index.
Kotlin